PHP: Using a variable inside a double quotes
$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.
PHP: Using a variable inside a double quotes with backshlashes
Just use string concatenation instead:
$file_name_with_full_path = 'C:\inetpub\wwwroot\upload\files\\' . $filnr . '\\' . $file;
Note you need to use \\
for the \
before the '
otherwise PHP treats it as an escaped '
.
If you want to use double quotes, you just need to escape all the backslashes that occur before something that can be interpreted as a variable (or a special character e.g. \f
= Formfeed):
$file_name_with_full_path = "C:\inetpub\wwwroot\upload\\files\\$filnr\\$file";
Demo on 3v4l.org
How to insert php variable inside a double quoted php string
You missed out the closing '
. Also, you need to concat them using the PHP concatenation operator .
to join the string with the variable:
$a['id'] = 1;
$html .= '<a href="' . $a['id'] . '">Link</a>';
How can I add single quotes to a variable in PHP
You can do
echo "\"$animal\"";
Or you can just use single quotes instead as the following:
echo '"$animal"';
Whichever you prefer.
PHP: how to add double quote to a PHP variable
Try this concatenation
echo '"' . $time . '"';
or use sprintf()
like so
echo sprintf('"%s"', $time);
How to insert a double quotes in a variable in php
Just add single quotes to your string which will do what you need:
$sql = "SELECT ID FROM loto_users WHERE email='".$email."' LIMIT 1";
But, if you really want double quotes, just escape them:
$sql = "SELECT ID FROM loto_users WHERE email=\"".$email."\" LIMIT 1";
Or, alternatively, don't concatenation:
$sql = "SELECT ID FROM loto_users WHERE email='$email' LIMIT 1";
$sql = "SELECT ID FROM loto_users WHERE email='{$email}' LIMIT 1";
Is there any way to use function in PHP double quote string?
No, sorry, there's nothing like that built into PHP.
The Strings documentation describes the kinds of substitutions that are done inside double-quoted strings and heredocs.
When a string is specified in double quotes or with heredoc, variables are parsed within it.
There are two types of syntax: a simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort.
The complex syntax can be recognised by the curly braces surrounding the expression.
...Complex syntax
Any scalar variable, array element or object property with a string representation can be included via this syntax.
Neither the simple nor complex syntax can be used to include a function call.
Related Topics
Php: Multiple SQL Queries in One MySQL_Query Statement
PHP Configuration: It Is Not Safe to Rely on the System's Timezone Settings
Difference Between Array_Map, Array_Walk and Array_Filter
Laravel Eloquent Sum of Relation's Column
PHP Get Url of Redirect from Source Url
Is It Necessary to Declare PHP Array Before Adding Values with []
How to Read Cookie/Session Value While Executing PHP5 Script Through Command Prompt
Only Variable References Should Be Returned by Reference - Codeigniter
Get Variable from PHP to JavaScript
How to Chain Method on a Newly Created Object
Get the Sum of All Digits in a Numeric String
Interface or an Abstract Class: Which One to Use
Best Way to Determine If a Url Is an Image in PHP
How to Get the Client's Ip Address in a PHP Webservice
Connecting to Remote MySQL Server Using PHP