Solved

echo "

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP: Query an Sqlite3 Datatbase return in JSON 6 52
mysqli insert query problems 4 22
comma true 6 34
How to submit record from external php form to a Sharepoint list? 5 35
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

803 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