Click to See Complete Forum and Search --> : Escaping quotes when using echo statements.


Nibinaear
January 21st, 2005, 03:12 PM
I've been using an echo statement to write my html code to the webpage, so to use double quotes in the html code, I have to escape them using \".

This is cumbersome and I need to find a better way. I'm thinking of using addSlashes(), but do I have to apply that to the whole of my script?

At the moment there is a problem with using this method, but I don't know what it is, the code just doesn't display correctly. What I really need is a way to get html documents, and change them to php really quickly and easily, is there a program that's good at doing that?

Here is my code:



<?
include ('header.php');

echo "
<!--Modules row-->
<tr>
<td width =\"200\" rowspan = \"5\" align = \"center\" valign = \"top\"><img src = \"corkboard.jpg\"/></td>

<td width =\"50%\" rowspan = \"5\">
<table border = \"1\" cellpadding = \"0\" cellspacing = \"0\" valign = \"top\" width = \"100%\" height = \"100%\">
<tr>
<td valign = \"top\" width = \"100%\" height = \"100%\">
Welcome to testing times.
<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;

</td>
</tr>
</table>
</td>

<td>&nbsp;</td>
<td class = \"twohundred\" colspan = \"3\" align = \"right\">
<img src= \"tornpaper.jpg\"/>
</td>
</tr>

<tr>
<td>&nbsp;</td>
<td class = \"twohundred\" colspan = \"3\" name = \"modules box\">

<table width = \"100%\" background = \"bg01.jpg\" height = \"100%\" border = \"1\" cellpadding = \"0\" cellspacing = \"0\">
<tr>
<td>
<ul type = \"square\">
<li/>CG115: E-Business & Web Management
<li/>CG551: Professional Development
<li/>CM512: Object Orientation
</ul>
</td>
</tr>
</table>

</td>
</tr>

<tr height = \"30\">
<td colspan = \"4\" name = \"right hand side\">&nbsp;</td>
</tr>



<!--tasks-->
<tr>
<td>&nbsp;</td>
<td class = \"twohundred\" width = \"200\" colspan = \"3\" name = \"right hand side\" align = \"right\">
<img src= \"tornpaper-tasks.jpg\"/>
</td>
</tr>

<tr>
<td>&nbsp;</td>
<td class = \"twohundred\" name = \"right hand side\" colspan = \"3\">
<table width = \"100%\" height = \"100%\" background = \"bg01.jpg\" border = \"1\" cellpadding = \"0\" cellspacing = \"0\">
<tr>
<td class = \"twohundred\">
<ul type = \"square\">
<li/>Add Assignment
<li/>Edit Assignment
<li/>Edit my details
<li/>Change my details
</ul>
</td>
</tr>
</table>
<P>&nbsp;<P>&nbsp;<P>&nbsp;
</td>
</tr>


</table>

</body>

</html>

";

?>

Mutilated1
January 21st, 2005, 05:43 PM
Here is how I like to do it...


<?php

include ("header.php");

function do_page() {
return <<<HTML

<h1>No need to escape "quotation" marks in here!</h1>
<h5>Make it as complicated as you like</h5>

HTML;
}

$page = do_page();
echo $page;

?>

visualAd
January 22nd, 2005, 04:34 AM
There is a reason why PHP is called an HTML embedded scripting language. Its because it can be embedded in HTML:

<?php include ('header.php') ?>
!--Modules row-->
<tr>
<td width ="200" rowspan ="5" align ="center" valign ="top">
<img src="corkboard.jpg" />
</td>

<td width="50%" rowspan ="5">
<table border="1" cellpadding="0" cellspacing="0" valign="top" width="100%" height="100%">
<tr>
<td valign="top" width="100%" height="100%">
Welcome to testing times.
<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;
</td>
</tr>
</table>
</td>

<td>&nbsp;</td>
<td class="twohundred" colspan="3" align="right">
<img src="tornpaper.jpg" />
</td>
</tr>

<tr>
<td>&nbsp;</td>
<td class="twohundred" colspan="3" name="modules box">
<table width="100%" background="bg01.jpg" height="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<ul type="square">
<li/>CG115: E-Business & Web Management
<li/>CG551: Professional Development
<li/>CM512: Object Orientation
</ul>
</td>
</tr>
</table>

</td>
</tr>

<tr height="30">
<td colspan="4" name="right hand side">&nbsp;</td>
</tr>



<!--tasks-->
<tr>
<td>&nbsp;</td>
<td class="twohundred" width="200" colspan="3" name="right hand side" align="right">
<img src= "tornpaper-tasks.jpg"/>
</td>
</tr>

<tr>
<td>&nbsp;</td>
<td class="twohundred" name="right hand side" colspan="3">
<table width="100%" height="100%" background="bg01.jpg" border="1" cellpadding="0" cellspacing="0">
<tr>
<td class="twohundred">
<ul type="square">
<li/>Add Assignment
<li/>Edit Assignment
<li/>Edit my details
<li/>Change my details
</ul>
</td>
</tr>
</table>
<P>&nbsp;<P>&nbsp;<P>&nbsp;
</td>
</tr>


</table>

</body>

</html>

Don't be afraid to embed PHP in HTML. Using massive echo statements not only wastes resources but also makes the code look untidy.