Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding Backslashes To PHP echo

Posted on 2013-01-29
4
Medium Priority
?
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
kmslogic earned 2000 total points
ID: 38832129
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
ID: 38832167
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
ID: 38832196
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
ID: 38832229
It's funny.  With everything being so complex that I am doing, finally a simple solution!
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

609 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