PHP - I need a way to replace square brackets with dynamic data -


i trying build system allow user enter amount of text in textarea field, within text entered, user enter "variable" in format [var], text var replace "variable" user needs such [amount], query database find amount user, need php script find square bracket variable , replace dynamic data.

can help?

regards, roddy

one of possible solutions:

$vars = array(     'username' => 'user1',     'foo' => 'bar' ); $text = "hello, [username]! test! [foo]"; foreach ($vars $k => $v) $text = str_ireplace("[".$k."]", $v, $text); echo $text; 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -