PHP - 将字符串转换为变量

PHP - Convert a string to a variable

我有一个像这样的字符串:

$string = 'my name is ';

是否可以将 $1 转换为变量来执行类似

的操作
$string = 'my name is ';
 = 'Ted';
echo $string ; 

输出:'my name is Ted'

谢谢!

使用str_replace:

echo str_replace('',,$string);

或者用双引号替换引号。

您需要使用printf功能。这是一个例子:

$number = 9;
$str = "Beijing";
printf("There are %u million bicycles in %s.",$number,$str);

这将转换为 "There are 9 million bicycles in Beijing"。

 = "ted";

echo "my name is "; //double quotes includes variables