Re: Help with regular expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Al wrote:
John Nichel wrote:

Carl Furst wrote:

Ok I am so stumped.. I'm doing something stupid and I can't figure it out..

Here's the code:

<?php

$eml = 'hiddenemailadddress@xxxxxxxxxxxxxxxx ceo'; if (strpos($eml, ' ')) echo "yep, there are spaces\n"; //does strpos see the
spaces?
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


Working fine on my end (copy/pasted your code)



$eml= trim($eml);

$pattern= "%\s%"; //I use % as delimiters, more obvious for me when debugging

if(preg_match($pattern, $eml) echo "yep, there are spaces\n";

preg_replace($pattern, '', $eml); echo "works now\n";

Sorry, left off the new $eml

$eml= preg_replace($pattern, '', $eml); echo "works now\n";

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux