Answer the question
In order to leave comments, you need to log in
How to replace a variable in text?
Let's say we have a script
<?php
$var = "значение";
$text = 'more text $var'; // не двойные кавычки, php не подменит
?>
Answer the question
In order to leave comments, you need to log in
Not very fast, but:
foreach($GLOBALS as $k=>$v) {
$text = str_replace('$'.$k, $v, $text);
}
$text = str_replace('$var', $var, $text);
$text = str_replace('$var2', $var2, $text);
$text = str_replace('$var3', $var3, $text);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question