PReg_replace,highlight_string HELP!

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
razno
Forum Newbie
Posts: 2
Joined: Mon May 16, 2005 5:58 pm

PReg_replace,highlight_string HELP!

Post by razno »

Hi guys.I need some help
I have this code

Code: Select all

$tekst=preg_replace(array('/(\[php\])(.+)(\[\/php\])/'),highlight_string($2,true),$tekst);
ANd wheni try to use it i don't get higlighted text.I get nubmer 2 in color.

How i can fix this?I was searching a lot but i can't find anything.Please help.I need this urgent
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Your variable can't start with a number, that's one of the number one rules of programming in any language.
razno
Forum Newbie
Posts: 2
Joined: Mon May 16, 2005 5:58 pm

Post by razno »

This is regex.Even if i use \\2 i get the same result
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The "$2" must be quoted in a string... it would actually give you errors like you have it if you have error reporting on. Same goes for "\\2"

Also... put a "?" after your ".+" because it's greedy and will match too much how you have it. You need the "s" and "e" modifier too.

Good luck!

PS: Moved to regex
Post Reply