You are here: RE: [PHP] Help with regular expressions « PHP « IT news, forums, messages
RE: [PHP] Help with regular expressions

Posted by "php-mail" on 10/04/17 11:37

I tested this with

$t = "string string";
preg_replace('/\s/', '', $t);
echo $t;

And the replace left a space... so then I tried this

$t = "string string";
$t = preg_replace('/\s/', '', $t);
echo $t;

And the output was spaceless (spaced out?)... maybe worth a try?

HTH

Dan
--

-----Original Message-----
From: Al [mailto:news@ridersite.org]
Sent: 17 January 2006 22:45
To: php-general@lists.php.net
Subject: Re: [PHP] Help with regular expressions

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@hiddendomain.net 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";

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

__________ NOD32 1.1369 (20060117) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация