Re: help with preg_replace please

From: Date: Wed, 26 Mar 2003 12:15:59 +0000
Subject: Re: help with preg_replace please
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-141078@lists.php.net to get a copy of this message
> I get the following error: > > Parse error: parse error, expecting T_VARIABLE' or xÓ$àkûÑ¿}ä¥JÒõ > R'$'' in > /usr/local/apache/htdocs/lib/lib_string.inc on line 218 > > Using this code: > $str = > preg_replace("!([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])!ei", > "<a > href=\"{$1}://{$2}{$3}\">{$2}{$3}</a>", $str); Since you're using the 'e' modifier, the "replacement" string needs to be valid PHP code. So, it should start with a variable or a function. A replacement such as: 'print("<a href="{$1} .. ")' should work. I didn't get a chance to answer you original question. I couldn't even get that regular expression to match links in any tests that I did, but if it's working for you, that's good. Couldn't you modify the expression to look for 0-60 characters that are not a space, followed by any amount of characters that are not a space, and only actually match the first 0-60 to use in your replacement string? Something like: ([^[:space:]]{0,60})[^[:space:]]* Which will match up to 60 characters in $2 for example, and also allow form more characters than that, but just not match them. This is assuming what everyone else said is right and you fix the entire regex to match the preg syntax... ---John Holmes...

« previous php.general (#141078) next »