note 12971 deleted from function.preg-replace by sniper

From: Date: Tue, 30 Sep 2003 12:28:35 +0000
Subject: note 12971 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57465@lists.php.net to get a copy of this message
Note Submitter: temple@asu.edu ---- Here is a little snippit to scan an html page load into a variable and replace spaces in linked phrases with &nbsp; I put a dash in to ensure it displays. $myhtml = preg_replace("/(<a.*?>|<A.*?>)(.*?)(<\/a>|<\/A>)/e", "'\\1'.str_replace(' ', '&nbsp;', '\\2').'\\3'", $myhtml); This can be altered to substitute spaces in the alt tag of an image as follows: $myhtml2 = preg_replace("/(alt=\"|ALT=\")(.*?)(\")/e", "'\\1'.str_replace(' ', '&nbsp;', '\\2').'\\3'", $myhtml); I found this useful when doing select space replacements rather than global replacements.

« previous php.notes (#57465) next »