Regex help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adamp
Forum Newbie
Posts: 1
Joined: Tue Mar 04, 2003 4:53 pm

Regex help

Post by adamp »

I'm having serious trouble getting a regular expression to work and would greatly appreciate any help.

I basically want to do stripslashes() on text in a string where it is between a {php} and {/php} tag.

A couple of things I've tried so far:

Code: Select all

$tmpl = preg_replace("!\{php\}(.|\s)+\{/php\}!e", "stripslashes('\\1')", $tmpl);
		$tmpl = preg_replace( "!\{php\}(ї^{]+)\{/php\}!e", "{php} stripslashes( '$1' ) {/php}", $tmpl );
Hopefully someone who understands regular expression better than me will have an answer :)
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

this works

Code: Select all

$tmpl = preg_replace('/{php}(.*){\/php}/', "$1" , $tmpl);
but not when strip slashes is used

I assume you'll need to split it up and do what you need and join it back together
Post Reply