Page 1 of 1

PHP Echo & HTML Code

Posted: Sat Jun 20, 2009 10:02 pm
by neomulemi6
Simple question, how can I circumvent having to place slashes in front of quotation marks to get PHP to echo HTML code correctly?

For instance, let's say I have this.
echo "<table border=\"0\">";

I recall seeing somebody circumvent this problem with something similar to the below.
<?
echo "
:>

<table border="0">

<:
";
?>

I don't recall the specifics of what exactly was placed where the ":>" and "<:" are. I know I can simple omit using quotation marks and the code would display just fine, however, this is not an acceptable solution for me. Any help would be greatly appreciated.

Thanks.

Re: PHP Echo & HTML Code

Posted: Sat Jun 20, 2009 11:14 pm
by requinix
You know you can use single-quotes instead?

Code: Select all

echo '<table border="0">';
// or the converse
echo "<table border='0'>";
For your original question, look into heredoc syntax.

Re: PHP Echo & HTML Code

Posted: Sat Jun 20, 2009 11:19 pm
by novice4eva
Maybe you saw heredoc syntax. Go through this link for it: http://www.php.net/manual/en/language.types.string.php.

Well it's not 100% solution but i tend to do this:

echo '<table border="0">';

everything inside single quote so then we don't have to escape double quotes, but then again if we need single quote somewhere in between, we will have to escape it!!

Re: PHP Echo & HTML Code

Posted: Sat Jun 20, 2009 11:29 pm
by neomulemi6
This is exactly what I was looking for! I thank you both. :D

Re: PHP Echo & HTML Code

Posted: Sun Jun 21, 2009 12:22 am
by Loki
Well sometimes if I have lot to echo, I either stick it in another file and include, or do something like this:

Code: Select all

 
if(condition == true) {
?>
--- content to echo here ---
<?php
} else {
whatever();
}