Re: [PHP] putting variables in a variable



On Mon, Mar 28, 2011 at 7:06 AM, Hulf <ross@xxxxxxxxxxxxxx> wrote:
Hi,

I am making and HTML email. I have 3 images to put in. Currently I have

$body .="
<table>
<tr>
<td><img src=\"image1.jpg\"></td>
</tr>

<tr>
<td></td>
</tr>
</table>
";


ideally I would like to have

$myimage1 = "image1.jpg";
$myimage2 = "image2.jpg";
$myimage3 = "image3.jpg";


and put them into the HTML body variable. I have tried escaping them in
every way i can think of, dots and slashes and the rest. Any ideas?

Consider HEREDOC syntax. I'm not sure why you're doing your
tables like that, but I'm sure you have your reasons. Also, I'm
certain that hardcoding the image names like that is just for example,
since it would be much easier to use an array or something similar (if
it's not coming from a database or otherwise dynamically-generated).

<?php

$myimage1 = "image1.png";
$myimage2 = "image2.png";
$myimage3 = "image3.png";

$body .=<<<EOT
<table>
<tr>
<td><img src="$myimage1"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><img src="$myimage2"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><img src="$myimage3"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
EOT; // This has to be at position one on the line, no matter what.
?>

And, for good measure, the array way:

<?php

$images = array('image1.png','image2.png','image3.png');

echo "<table>\n";

foreach($images as $p => $v) {
$body .=<<<EOT
<tr>
<td><img src="$v"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>

EOT; // Notice the blank line. That ensures a linebreak after the last </tr>
}

echo "</table>\n";
?>

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
.



Relevant Pages

  • Re: [PHP] returning the index number part2
    ... On Tue, June 5, 2007 11:16 am, blueboy wrote: ... if I have an array of 3 images ... PHP General Mailing List ...
    (php.general)
  • Re: OT Camera Raw 5.2 and Photoshop CS4, not CS3
    ... used at the loop boundaries. ... will lay out an array in memory. ... But if the the compiler sets the array in memory as 8 blocks of 6 reals, ... Instead it can be quite slow on large images. ...
    (rec.photo.digital.slr-systems)
  • Re: Loading png images into a mysql table/database
    ... echo $data; ... Loading images from a dB is really lame! ...
    (comp.lang.php)
  • Re: Preload images
    ... Now there is only one array of images which looks ... Avoid global variables. ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Re: [PHP] corrupt image when viewed using PHP
    ... You can find different solutions at the PHP Manual web site; ... We have written an app in PHP4 that receives images from mobile phones that are taken with the camera, we have found a problem that some of the images ... are corrupt and we have determined that it is because of Nokia VGA cameras that have sent the image, basically the jpegs are fine but the extra info that comes with the jpeg is corrupt, therefore PHP wont open the image, with all other photos its fine. ... We also found another possible solution being that we use ImageMagick to convert the jpeg to a jpeg, ...
    (php.general)