• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How do I store the contents of this php echo into a variable?

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
I want to store the contents of this echo into one big variable called $emailText. Not too sure how to do it.

Code:
echo 
'VLP Photography Job: <a href="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='.$_POST["address"].'" target=_blank>'.$_POST["address"].'</a>
<br/><br/><b>Type of Job:</b><br/><br/>'
.
'<a href="'
.
$joblink
.
'" target="_blank">'
.
$_POST["typejob"]
.
'</a>'
.
'<br/><br/><b>Address:</b><br/><br/>'
.
$_POST["address"]
.
'<br/><br/><b>Time:</b><br/><br/>'
.
$_POST["time"]
.
'<br/><br/><b>Client:</b><br/><br/>'
.
$_POST["realtor"]
.
'<br/><br/><b>Photographer Notes:</b><br/><br/>'
.
$formattednotes
.
'<br/><br /><b>Thank you!</b>
<br />-Victor
<br />victor@victorlinphoto.com
<br />http://www.victorlinphoto.com
<br />650.248.0289'
 
From the console? It would be something like php myphpapp.php > outputfile.txt

No, in the code itself.

Basically, I coded it originally to echo all that stuff. Now I don't want it to echo it, but instead store it all as a variable.
 
Think about what you've done here. You've created an echo command that takes...what? A string. A very long string, but just one string nonetheless.

So assign that string to a variable instead.
 
$my_echo = 'x'
. 'y'
. 'z' ;

If the PHP interpreter gets tired after 30 or 40 lines, you can always let it start over with the adding and concatenating and appending by using '.=' instead of just '=':

$my_echo .= 'x2'
. 'y2'
...
. 'z42' ;
 
Last edited:
I figured it out. All I needed to do was replace echo with $messagetext= and make sure there was a ; at the end.

What was screwing me up was that I was trying to add " around the whole thing, like if I were to do:

$messagetext = "Message text.";

Adding quotes messed things up.
 
Back
Top