Page 1 of 1
results in double quoted strings
Posted: Sat Aug 25, 2007 7:23 am
by paulkd
I'm from a ColdFusion background. I would like to know if it is possible to display the results of a function within a double quoted string. ie not using a dot to concatenate.
Coldfusion:
Code: Select all
<cfset astring="todays date is #now()#">
PHP:
Code: Select all
$astring = "todays date is getDate()";
I know I can assign a variable and embed it in the double quoted string, but I would like to simply embed the results of the function.
Posted: Sat Aug 25, 2007 10:27 am
by smudge
Did you check
the manual? I'm sure it has an answer for you, but as far as I know, you can't
Re: results in double quoted strings
Posted: Sat Aug 25, 2007 12:34 pm
by superdezign
paulkd wrote:I'm from a ColdFusion background. I would like to know if it is possible to display the results of a function within a double quoted string. ie not using a dot to concatenate.
No. When you put data into a double quoted string, PHP first looks for the '$' token (or a combination of braces and the '$' token, i.e. '{$...}') up to the first invalid character for a variable (or the closing bracket if you use it), which consists of non-alphanumeric characters. Then, it replaces that portion of the string with the data in the variable being referred to.
Posted: Sat Aug 25, 2007 12:43 pm
by Benjamin
Your looking for:
Code: Select all
$astring = "todays date is " . getDate();
Re: results in double quoted strings
Posted: Sat Aug 25, 2007 12:44 pm
by califdon
paulkd wrote:I'm from a ColdFusion background. I would like to know if it is possible to display the results of a function within a double quoted string. ie not using a dot to concatenate.
Coldfusion:
Code: Select all
<cfset astring="todays date is #now()#">
PHP:
Code: Select all
$astring = "todays date is getDate()";
I know I can assign a variable and embed it in the double quoted string, but I would like to simply embed the results of the function.
You can't do it like you showed as an example, but you can do it this way, using the concatenation operator
. :
Code: Select all
$astring= "todays date is " . getDate();