Solved

echo "

Posted on 2013-11-10
3
440 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 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 109

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Toggle & Anchor Links 5 43
Row insertion failed. Array 5 48
Wordpress Pagination 1 30
show child records separated by commas 12 11
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…

830 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