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
Post a Comment