How to store PHP and HTML code to a variable?
Posted 03 September 2006 - 11:32 AM
php:<a href="hr0.php?p=<? echo $p; ?>">Introduction</a>
I have the code to randomly pick a number, then the HTML code to display that story and any assossciated images is loaded into a variable. This is all done in a separate file from the page where it will be displayed (as it will be used to fill the sideboxes of many pages.) In the sidebox I also want to include a link, so if the user is interested they can click it and be taken straight to the page. However, I am having trouble because it doesn't work having php code, within html code, being loaded into a php variable and then echoed. This is the code within my random picking file that loads the variable that I want to echo on my target page:
$body = "<p align=\"center\"><img src=\"images/l2-019.jpg\" width=\"155\" height=\"156\" /></p>
<p align=\"center\"> <a href=\"hr0.php?p=<? echo $p; ?>\">Introduction</a>"
This works and does show the image and word "introduction" but upon clicking it the colour reverts to the default.
Any ideas please?
Posted 03 September 2006 - 11:36 AM
$body = '<p align="center"><img src="images/l2-019.jpg" width="155" height="156" /></p> <p align="center"> <a href="hr0.php?p=' . $p . '">Introduction</a>';
Posted 03 September 2006 - 12:52 PM
Posted 03 September 2006 - 12:54 PM
Posted 03 September 2006 - 04:11 PM
Also I use single quotes on html blocks to save having to type the backslash . This also helps keep the code a readable as possible.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users