Solved

Adding Backslashes To PHP echo

Posted on 2013-01-29
4
504 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

806 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