PHP - single and double quotes - the difference
Topics

--><!-- Nothing works without HTML -->



<div>

<h1>PHP - single and double quotes - the difference</h1>


<img src="../images_July_2015/hello.png" width="600" height="287" alt="function php"/>
<h6>There's a button below (sneak peek) to peek at the code.</h6>




<div>Php says:</div>


<?php
$variable = "sugar";
echo "<p>$variable</p>";
echo "\n";//makes next paragraph go to new line
echo '<p>$variable</p>';
?>


<p>This is sent to the browser:</p>

<img src="../images_July_2015/php_1_code3.png" width="248" height="186" alt="" border="0">


<p>
It is easy to see what the single quote does.
Now what if you need quotes in quotes?
It would look like this:
</p>






<div>Php says:</div>


<?php
echo "'sugar'";
echo "<br/>";
echo ("or");
echo "<br/>";
echo '\'sugar\'';//you have to "escape" the quotes with "\"
echo "<br/>";
echo ("or");
echo "<br/>";
echo '"sugar"';
echo "<br/>";
echo ("or");
echo "<br/>";
echo "\"sugar\"";
?>

<p>But what happens if you add a variable. Let's take a look:</p>

<div>Php says:</div>

<?php
$variable = "sugar";
echo "'sugar and $variable'";
echo "<br/>";
echo ("or");
echo "<br/>";
echo '\'sugar and $variable\'';//you have to "escape" the quotes with "\"
echo "<br/>";
echo ("or");
echo "<br/>";
echo '"sugar and $variable"';
echo "<br/>";
echo ("or");
echo "<br/>";
echo "\"sugar and $variable\"";
?>



</br>
</br>

<a href="http://www.primitivecode.com/index.php?topic=-PHP-concatenation-in+php-">
&gt;&gt; continue</a>


<br/>
<br/>
<br/>
<?php $Weblog->share ();?>


<br/>
<br/>
<br/>

</div>

Sneak peek of the server side code