how to replace a placeholder in a string?

后端 未结 4 2066
臣服心动
臣服心动 2021-01-08 01:06

Not very sure how to word this question but I\'ll give an example.

$string = \'Hey, $name. How are you?\'; 

When I post this string,

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-08 01:28

    You should be wrapping the string in double quotes (") if you want variables to be expanded:

    $name = "Alica";
    $string = "Hey, $name. How are you?"; // Hey, Alica. How are you?
    

    See the documentation.

提交回复
热议问题