How to echo three levels of nested quotes PHP

This article was written by in June 27, 2014, & may not be posted on other sites!
Original source url for this article: How to echo three levels of nested quotes PHP

How to echo three levels of nested quotes php?
Sometimes you need to nest quotes in php in two or three levels. This is how to echo nested quotes in PHP:
First level use ‘

Second level use “
Third level use \’

How to echo three levels of nested quotes php

 

Echo one level of quotes in php

A basic echo in php looks like this:
<?php echo('hello world'); ?>

 

Echo two levels of nested quotes php

An echo with two levels of quotes looks like this. Just use a double quote inside a single quote, or a single quote inside a double qoute, something like this:
<?php echo('<p id="myId">hello world</p>'); ?>

 

Echo three levels of nested quotes php

To echo three levels of quotes in php you need to add a \ before the third guote characters. Something like this:
<?php echo('<p id="myId" onClick="this.className=\'clicked\'">hello world</p>');

First level use ‘
Second level use “
Third level use \’

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *