Solved

echo "

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

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
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
Comment Utility
Unfortunatelly no, it's the easiest way.. This is a common issue in many languages due to the syntax.. Annoying, indeed
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now