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.
PHP Echo & HTML Code
Moderator: General Moderators
Re: PHP Echo & HTML Code
You know you can use single-quotes instead?
For your original question, look into heredoc syntax.
Code: Select all
echo '<table border="0">';
// or the converse
echo "<table border='0'>";- novice4eva
- Forum Contributor
- Posts: 327
- Joined: Thu Mar 29, 2007 3:48 am
- Location: Nepal
Re: PHP Echo & HTML Code
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!!
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!!
-
neomulemi6
- Forum Newbie
- Posts: 3
- Joined: Sat Jun 20, 2009 9:56 pm
Re: PHP Echo & HTML Code
This is exactly what I was looking for! I thank you both. 
Re: PHP Echo & HTML Code
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();
}