Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

echo "

Posted on 2013-11-10
3
Medium Priority
?
445 Views
Last Modified: 2013-11-10
Ok, really simple question Ive sure, however its one that Ive worked around, but would like another solution


In the past when Ive needed to break a string to insert a " Ive either done:-

a) echo "This is a " . chr(34) . "\n";

or

b) echo 'This is a " \n';

What I wondered is there an easier way to put " and other reserved characters into a string, such as \" or ""
0
Comment
Question by:tonelm54
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 39636902
You can surely escape special chars:
echo "This is a \"quoted\" sring";

Open in new window


or you can also use heredoc syntax:

echo <<<STR
  This is a "quoted" string, and this is teh call to a variable {$_POST['variable']}
STR;

Open in new window


As a side note, it's now discouraged to access global variables in $_GET, $_POST, $_REQUEST and $_SESSION directly: use filter_input and filter_var instead.
0
 

Expert Comment

by:Al_K
ID: 39636903
Unfortunatelly no, it's the easiest way.. This is a common issue in many languages due to the syntax.. Annoying, indeed
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39637036
This article may help...
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

In the case of \n you're almost always better off using PHP_EOL, which is the predefined and context-aware end-of-line character.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 count occurrences of each item in an array.
Suggested Courses

963 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