Solved

Adding Backslashes To PHP echo

Posted on 2013-01-29
4
501 Views
Last Modified: 2013-01-29
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
Comment
Question by:DS928
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
kmslogic earned 500 total points
Comment Utility
Well just put a backslash in there.  If you need to escape a backslash add another backslash.

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

Author Comment

by:DS928
Comment Utility
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
 
LVL 16

Expert Comment

by:kmslogic
Comment Utility
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
 

Author Closing Comment

by:DS928
Comment Utility
It's funny.  With everything being so complex that I am doing, finally a simple solution!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to resize preview image 4 28
Button Click 11 24
lastpass auto fill login form 5 22
update field on focusout 15 19
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now