preg_replace and eval
| From: | Daniel Pupius | Date: | Mon, 28 Oct 2002 10:56:26 +0000 |
| Subject: | preg_replace and eval | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-121674@lists.php.net to get a copy of this message | ||
Hey there,
We have a class that sets up a tree structure that represents an e-learning
object made up of nested "components". We have a function
getPropertyValue($name) which returns the property $name for the current
component.
Now, we want to allow the user to use something like {parent.property} in a
property value, so that it can inherit parts of properties from the parent
component. For example: caption = "the name of this component's parent is
{parent.name}!"
The following line sort of works:
$retVal =
preg_replace("/(.*){parent.(.*)}(.*)/e","'\\1'.\$this->parentNode->getProper
tyValue('\\2').'\\3'",$retVal);
However, if there are more than one string to replace it only works on the
last one. So:
caption = "the parent's coordinates are ({parent.left}, {parent.top})" would
only return something like: "the parent's coordinates are ({parent.left},
100)"
Hope someone can help.
Thanks
Dan