Back Slashes

Hello,

Still learning PHP and came across these examples:

[php]echo "<a href=“index.php?content=register”>Try again
;

echo "<a href=“index.php”>Return to Home;[/php]

AND

[php]echo "<input name=“goButton” type=“submit” value=“browse” />;
echo "<input name=“content” type=“hidden” value=“edit” />;[/php]

My question is: What purpose or function do all the back slashes serve?
Can’t it be just :
[php]echo "<input name=“goButton” type=“submit” value=“browse”[/php]
–without all the backslashes?

Thanks in advance.
-Chris

hello Chris, if you are trying to echo any html tag using double quote's as below echo ""; in above case you must need to use back slashes with attributes of tag. In above case you hvae to you below syntax echo "";

if you do not want to use back slashes than do this
Always start you echo syntax with single quote like this
echo ‘’;

In short you i can say if your echo syntax is started with double quote’s and you are also using double arround double qoute arround attibute of input tag. than you must use back slashes.
So it’s always better to start echo syntax with single quote’s

I helpful for you
SR

You can’t do like quotes because php will interprete it as a string termination.

if you try to do echo “Return to Home”;, it will think that “<a href=” is an unterminated string, which will give you a missing ; error. The \ just escapes the quote, telling php to ignore it. you can also do “Return to Home”;. Either way will return acceptable html code.

I hadn’t logged back in till now (busy with work) but thank you, Sarthak Patel and richei!
Chris

Sponsor our Newsletter | Privacy Policy | Terms of Service