Solved

echo "

Posted on 2013-11-10
3
443 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
[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
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 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 110

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 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