PHP: Using a variable inside a double quotes

后端 未结 2 1738
长情又很酷
长情又很酷 2020-11-27 07:11

please check the following code.

$imagebaseurl = \'support/content_editor/uploads/$name\';

The $imagebaseurl is a variable th

2条回答
  •  广开言路
    2020-11-27 07:26

    $imagebaseurl = 'support/content_editor/uploads/' . $name;
    

    or

    $imagebaseurl = "support/content_editor/uploads/{$name}";
    

    Note that if you use double quotes, you can also write the above as:

    $imagebaseurl = "support/content_editor/uploads/$name";
    

    It's good though to get in the habit of using {$...} in double quotes instead of only $..., for times where you need to insert the variable in a string where it's not obvious to PHP which part is the variable and which part is the string.

    If you want the best performance, use string concatenation with single quotes.

提交回复
热议问题