Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    php
  » Single Quote vs. Double Quote
      by Admin
 Page 1 of 1 
   

(Login to remove green text ads)
I recently ran into this little bit of info when working on some code to replace line breaks in a string with some HTML code....

When quoting attributes PHP (Perl as well) treats values wrapped by single quotes as there face value, it will not replaced variables or treat special characters how you would expect. When using double quotes variables are replaced and special character sets are treated normaly.

Here is an example:

PHP Code:
<?
$FeaturesFixed 
"this
is
the
features
code"
;

$FeaturesFixed ereg_replace ("\n""<li>"$Features);

echo(
" <li>$FeaturesFixed");
?>
Code:
<li>this
<li>is
<li>the
<li>features
<li>code
now with single quotes

PHP Code:
<?
$FeaturesFixed 
ereg_replace ('\n''<li>'$Features);

echo(
" <li>$FeaturesFixed");
?>
Code:
<li>this
is
the
features
code





 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting