My Stuff
Username

Password

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


Single Quote vs. Double Quote


Your rating: None Average: 4 (1 vote)

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:

<?
$FeaturesFixed = "this
is
the
features
code";
 
$FeaturesFixed = ereg_replace ("\n", "<li>", $Features);
 
echo(" <li>$FeaturesFixed");
?>
<li>this
<li>is
<li>the
<li>features
<li>code 

now with single quotes

<?
$FeaturesFixed = ereg_replace ('\n', '<li>', $Features);
 
echo(" <li>$FeaturesFixed");
?>
<li>this
is
the
features
code

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [asp], [awk], [c], [cpp], [csharp], [drupal5], [drupal6], [java], [javascript], [jquery], [mysql], [perl], [perl6], [php], [python], [ruby], [sql], [vb], [vbnet], [xml].
  • Use to create page breaks.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.