Re: Help with regular expressions
| From: | Al | Date: | Wed, 18 Jan 2006 00:43:16 +0000 |
| Subject: | Re: Help with regular expressions | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-228737@lists.php.net to get a copy of this message | ||
Al wrote:
John Nichel wrote:Sorry, left off the new $eml $eml= preg_replace($pattern, '', $eml); echo "works now\n";Carl Furst wrote:$eml= trim($eml);Ok I am so stumped.. I'm doing something stupid and I can't figure it out.. Here's the code: <?phpWorking fine on my end (copy/pasted your code)$eml = 'hiddenemailadddress@hiddendomain.net ceo'; if (strpos($eml, ' ')) echo "yep, there are spaces\n"; //does strpos see thespaces? echo preg_replace('/\s/', '', $eml); //WTF? Preg_replace does not? echo "$eml\n"; ?> As you can see there are a bunch of spaces in that email address. I'm trying to use preg_replace to get rid of them. Strpos sees the spaces and the first echo statement is executed. The second echo prints nothing and the third prints the original $eml with nothing substituted. Can anyone see why the perl reg isn't seeing the spaces? Carl$pattern= "%\s%"; //I use % as delimiters, more obvious for me when debuggingif(preg_match($pattern, $eml) echo "yep, there are spaces\n"; preg_replace($pattern, '', $eml); echo "works now\n";