• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Adding Backslashes To PHP echo

I have an echo statement that has three results.  I have spaces between each and I would like to add backslashes.  How would I do this?

echo $thecity.'  '.$thearea.'  '.$thecuisine;

Open in new window


Results:
Boston    Back Bay    American(New)

I would like:
Boston  \  Back Bay  \  American(New)

Thank you.
0
DS928
Asked:
DS928
  • 2
  • 2
1 Solution
 
kmslogicCommented:
Well just put a backslash in there.  If you need to escape a backslash add another backslash.

echo $thecity.' \\ '.$thearea.' \\ '.$thecuisine;
0
 
DS928Author Commented:
Thank you.  I don't know why I didn't try the most simple solution!  Being new to this.  What do you mean by escape a backslash?
0
 
kmslogicCommented:
The backslash key is used to handle certain escape sequences, for example

echo "\t" yields a tab character.  So with double quoted strings especially you need to escape the escape or put a double backslash when you want to see just one.

In the case of a single quote quoted string you can just put a single backslash or a double backslash and in both cases it will appear as a single backslash when it is output.
0
 
DS928Author Commented:
It's funny.  With everything being so complex that I am doing, finally a simple solution!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now