PHP preg_replace regex question -


i need figuring out regular expression. in script have line placeholders. want want send every placeholder text function translates should be.

e.g. text is:

lorem ipsum dolor sit {{ametplaceholder}}, consectetur adipiscing elit.

i want text ametplaceholder send of function translateme.

i bad in regex gave try anyways. don't further this:

$sstring    = preg_replace("(*.?)/\{{(*.?)}}(*.?)/", $this->echotext('\\2'), $sstring); 

which off course doesn't work.

can me out?

br, paul peelen

using preg_replace_callback, can specify method this:

 = preg_replace_callback("@{{(.*?)}}@", array($this, "echotext"), $txt) 

and method be:

 public function echotext($match) {      list($original, $placeholder) = $match;   // extract match groups      ...      return $translated;  } 

btw, designing regular expressions check out http://regular-expressions.info/ or of tools listed in: https://stackoverflow.com/questions/89718/is-there-anything-like-regexbuddy-in-the-open-source-world


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -