Web Hosting Talk







View Full Version : Simple preg_replace error


azizny
06-29-2006, 12:09 PM
I am converting from one system to another, the text on the old system has BB code such as:

PHP CODE[/php:2kiujh345]

[hide:2kiujh345]PHP CODE[/hide:2kiujh345]

and so on, I want to remove the extra :NUMBERS from the text, so I created this:

[php]
$new_text = preg_replace('/(.*)(\[hide.*\])(.*)(\[\/hide.*\])(.*)/i','$1$3$5',$old_text);


problem is that it will pick up on anything containing hide.

any help would be appreciated,

Peace,

jimpoz
06-29-2006, 04:53 PM
Maybe

$new_text = pregi_replace('\[(\/?[^\:]+)\:.*?\]', '[$1]', $old_text);

azizny
06-30-2006, 04:52 PM
worked like a charm (after adding delimiter and preg_replace instead of pregi_replace :D).

thanks,