Re: preg_replace() help

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

 



What do you want out?

$txt = 'A promise is a debt. -- Irish Proverb'; =>

[1] $txt = 'A promise is a debt. --Irish Proverb';

OR [2] $txt = 'A promise is a debt. --IrishProverb';

for [1] $txt= preg_replace("%--\x20+%", '--', $txt); //The \x20+ is one or more spaces



Rick Pasotto wrote:
I have quotes like the following:

$txt = 'A promise is a debt. -- Irish Proverb';

I'd like to replace all the spaces afer the '--' with  

This is what I've tried:

	$pat = '/( --.*)(\s|\n)/U';
    $rpl = '$1$2 ';
    while (preg_match($pat,$txt,$matches) > 0) {
        print "$txt\n";
        printf("[0]: <%s>\n",$matches[0]);
        printf("[1]: <%s>\n",$matches[1]);
        printf("[2]: <%s>\n",$matches[2]);
        preg_replace($pat,$rpl,$txt);
    }

The prints are for debugging. $matches contains what I expect but
nothing gets replaced and $txt stays the same so it loops forever.

What am I doing wrong?


--
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