Re: [PHP] help with preg_replace please
I get the following error: Parse error: parse error, expecting `T_VARIABLE' or `'$'' 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... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] help with preg_replace please
Hi, Total newbie on reg exps, and even worse with preg!!! I get the following error: Parse error: parse error, expecting `T_VARIABLE' or `'$'' 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); Can anyone point to the problem? The aim is to perform functions on $2 $3. TIA Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with preg_replace please
On Wednesday 26 March 2003 13:59, Justin French wrote: Parse error: parse error, expecting `T_VARIABLE' or `'$'' 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); You seem to be using ereg syntax in a PCRE function! Replace them with their proper PCRE counterparts. Eg to match alphanumeric: [0-9|a-z|A-Z] // off the top of my head, untested etc. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Real Users never know what they want, but they always know when your program doesn't deliver it. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with preg_replace please
what that guy said, or use ereg_replace instead of preg_... From: Jason Wong [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [PHP] help with preg_replace please Date: Wed, 26 Mar 2003 14:08:44 +0800 On Wednesday 26 March 2003 13:59, Justin French wrote: Parse error: parse error, expecting `T_VARIABLE' or `'$'' 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); You seem to be using ereg syntax in a PCRE function! Replace them with their proper PCRE counterparts. Eg to match alphanumeric: [0-9|a-z|A-Z] // off the top of my head, untested etc. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Real Users never know what they want, but they always know when your program doesn't deliver it. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with preg_replace() , PLEASE
I'm going mad about this. Now, i've got the following text: - BEGIN TEXT -- Let's see a very simple class sample ? class CTest { var $variable1; //Propiedad function DoThing()//Método { echo esto es una prueba de clase; echo una clase es mejor que nada; } } ? And this was the sample -- END TEXT --- I'm using preg_replace() to replace the PHP code qith the result of doing a highlight_string() to it. So i use this code: preg_replace(/(.*)(\?.*?\?)(.*)/imse,'\\1'.highlight_string('\\2').'\\3 ',$text); It ouputs this: ? class CTest { var $variable1; //Propiedad function DoThing()//Método { echo 'esto es una prueba de clase'; echo 'una clase es mejor que nada'; } } ? In colored code, as you might see. and the weirdest of all: when i use this code: preg_replace(/(.*)(\?.*?\?)(.*)/imse,''.highlight_string('\\1').''.high light_string('\\2').''.highlight_string('\\3').'',$text); It recognizes the \\1 and \\3 strings Why can't i use then preg_replace(/(.*)(\?.*?\?)(.*)/imse,''.strtolower('\\1').''.highlight_ string('\\2').''.strtolower('\\3').'',$text]); or even a simpler preg_replace(/(.*)(\?.*?\?)(.*)/imse,'\\1'.highlight_string('\\2').'\\3 ',$text); I'm trying to separate the code from the rest of strings, as you might see. Can anyone help me? I got this far, and i feel it's a very silly thing, but i can't seem to be able to get it. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php