Jump to content

Backslash


Aphp73

Recommended Posts

\' <= escapes the character that comees after it!

You really don't ever need to use them in a example like yours. If you use double quotes inside the variable assignment or language construct, just use single quotes to enclose it, doing the opposite, just reverse what I said previously!

example...

double inside, single enclose

[code]echo '<form action="" method="post">';[/code]

single inside, double enclose

[code]echo "<form action='' method='post'>";[/code]

Of course there will be times you made need to use the escape or backslash, like when you may need to quote a name O\'Hare or other types of strings that are using ([b]'[/b], [b]"[/b]) as there enclosing character!

Link to comment
https://forums.phpfreaks.com/topic/27197-backslash/#findComment-124411
Share on other sites

Even working with 2 different kinds of quotes can become really complicated.
I mostly echo html or javascript like:

[code]
<?php

$output = <<<HTML
<form action="" method="post">
    <input type="hidden" name="hidden1" value="$value">
</form>
HTML;

echo $output;

?>
[/code]

Like this you avoid working with different kind of quotes nesting in eachother, it can still occur but its rather an exception.
Link to comment
https://forums.phpfreaks.com/topic/27197-backslash/#findComment-124416
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.