PHP Echo & HTML Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neomulemi6
Forum Newbie
Posts: 3
Joined: Sat Jun 20, 2009 9:56 pm

PHP Echo & HTML Code

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Echo & HTML Code

Post 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.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: PHP Echo & HTML Code

Post 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!!
neomulemi6
Forum Newbie
Posts: 3
Joined: Sat Jun 20, 2009 9:56 pm

Re: PHP Echo & HTML Code

Post by neomulemi6 »

This is exactly what I was looking for! I thank you both. :D
Loki
Forum Commoner
Posts: 25
Joined: Wed Jun 03, 2009 9:23 pm

Re: PHP Echo & HTML Code

Post 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();
}
 
Post Reply