Escape codes

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
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Escape codes

Post by sheepz »

:oops:
I'm sorry i'm very new, just learning about PHP. There are escaping codes for special characters like if i wanted to output this display on a browser:

<?

echo <p> Special \"characters\" like greater than sign <em> </p>;

?>

I cannot get the <em> to output onto my screen is there a delinating character? thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

to output the html entities use htmlentities()

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.ter than sign ".htmlentities("<em>")."</p>";

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.ities]htmlentities()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.cial \"characters\" like greater than sign &quote;.htmlentities(&quote;&lt;em&gt;&quote;).&quote;&amntities]htmlentities()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.;lt;p> Special \"characters\" like greater than sign ".htmlentities("<em>").&quote;mp;gt; Special \"characters\" like greater than sign ".htmlentities("<em>")."&amp entities use htmlentities()

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.l=http://php.net/htmlentities]htmlentities()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.;amp;lt;em>")."</p>";

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.uote;.htmlentities("<em>")."</p>";

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.ies()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.>")."</p>";

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.9c4]echo "<p> Special \"characters\" like greater than sign ".htmlentities( entities use htmlentities()

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.p://php.net/htmlentities]htmlentities()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.".htmlentities("<em>").&quote;&lt;/p>";

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.p.net/htmlentities]htmlentities()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.;quote;;

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.mlentities()[/url]

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking. entities use htmlentities()

Code: Select all

echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";
Sorry if this wasn't what you wanted, sort of unclea256d9c4]echo "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";

Sorry if thiecho "<p> Special \"characters\" like greater than sign ".htmlentities("<em>")."</p>";

Sorry if this wasn't what you wanted, sort of unclear as to specifically what you were asking.
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

Sorry I was unclear. The result is i would like to use PHP language to display exactly this

Demonstration of using <br> tag

This is what I have:

<?
echo "Demonstration of using <br> tag"
?>

This is saved as "test.php" and my output is exactly this:

Demonstration of using
tag

I would like my output to say:

Demonstration of using <br> tag

I'm not exactly sure how to do it =\
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

I'm sorry I just figured it out. Your exactly right

".htmlentities("<em>")."

I thought the ("<em>").]" was just a period and was not part of the code. I kept getting errors because I left out that period. Thanks!
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

I'm sorry just another question. How would I display this exactly

Demonstrating how to use "<br>" in PHP


The quotes are not being displayed
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

echo htmlentities(&quote;Demonstration of using \&quote;&lt;br&gt;\" tag");
ion of using \"<br>\" tag");
a76608b]ation of using \"<br>\" tag");
quote;);
/php]
echo htmlentities("Demonstration of using \"<br>\" tag");
es("Demonstration of using \"<br>\&quote; tag&quote;);
amp;quote;<br>\" tag");
amp;gt;\" tag");

echo htmlentities("Demonstration of using \"<br>\" tag");
mp;quote;Demonstration of using \"<br>\" tag");
te;Demonstration of using \"<br>\" tag");
sing \"<br>\" tag");
");

echo htmlentities("Demonstration of using \"<br>\" tag");
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

The only characters that need to be escaped to be echo'd to the browser are " and ' depending on your syntax.

example

Code: Select all

$string = "John said, \"PHP Rocks!\", in a whisper.";

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';
The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is < and > is > and & is &. However the php function htmlentities() does this for you if you'd prefer to do it that way.mp;quote;, in a whisper.";

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';


The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is < and > is > and & is &. However the php function htmlentities() does this for you if you'd prefer to do p function htmlentities() does this for you if you'd prefer to do it that way. the browser are " and ' depending on your syntax.

example

Code: Select all

$string = "John said, \"PHP Rocks!\", in a whisper.";

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';
The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, = "John said, \"PHP Rocks!\", in a whisper.&quote;;

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';


The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is &lt; ato the browser are " and ' depending on your syntax.

example

Code: Select all

$string = "John said, \"PHP Rocks!\", in a whisper.";

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';
The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is < and > is > and & is &. However the php function htmlentities() does this for you if you'd prefer to do it that way.s enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is < and > is > and & is &. However the php function htmlentities() does this for you if you'd prefer to do it that way. that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is < and > is > and & is &. However the php function htmlentities() does this for you if you'd prefer to do it that way.cf8c0f8669]
$string = "John said, \"PHP Rocks!\", in a whisper.";

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';


The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is &lt
$string = "John said, \"PHP Rocks!\", in a whisper.";

// OR

$string = 'John said, \'PHP ROCKS!\', in a whisper.';


The only difference above is the single or double quotes you're enclosing your value in, and whether you want to print double or single quotes to the browser. If you must use the same quote that your value is enclosed in, escape it.

If you want to print out your HTML to the browser, you must use the entity for that character. For example, < is &lt; and > is &gt; and & is &amp;. However the php function htmlentities() does this for you if you'd prefer to do it that way.
Post Reply