[thelist] quoting attributes was not filling total width

Mike Migurski mike at cloudfactory.org
Wed Apr 18 20:18:26 CDT 2001


>Jonathon Isaac Swiderski wrote:
>> if i recall what i've read correctly, PHP doesn't care about single vs.
>> double quotes;
>
><snips>
>> that is, echo('bob') and echo("bob") do the same thing, so
>> long as you pair like with like.  thus, you can use single quotes, like so:
>> 
>> print     '<tr><td width="100%">';
>
>Usually, that's fine. The kicker is if you have a variable in there,
>single quotes and double quotes aren quite different:
>
>
><?php
>$world="world";
>echo 'hello $world';
>echo "<br>";
>echo "hello $world";
>?>
>
>Produces:
>hello $world
>hello world
>
>The first chapters in the manual on the PHP site are pretty good for
>this backgroundy stuff. It's worth revisiting as your skills develop. I
>find as I learn more, that in going to back to material I pick up things
>I missed in first passes.

The simple-explanation-for-newbies is that single- and double-quotes have
different meanings. Single quotes enclose data that is a simple string, so
characters such as double quotes and dollar signs can be enclosed. Single
quotes are suitable for use with long strings of text that only needs to
be echoed. Double quotes enclose data that can be parsed: \n's get
replaced with line breaks, \'s are used to escape the following character,
$variable_name and $array_name['key']'s get replaced with their associated
variables, and so on. Double quotes are suitable for strings that require
lots of inline data.

To eliminate the need for copious escaping of quotes, I often use syntax
like this:

	$string =
		'<p> the variable name is: ' . $variable_name
		. ' and its value is: ' . $variable_value . '</p>';

...it has the added benefit of maintaining nice syntax coloring in BBEdit.
:)

-mike.

--------------------------------------------------------------------------
                   michal migurski     mike at cloudfactory.org
                  tel:415.385.1993     AIM:migurski
    http://www.viberation.com/mike     ICQ:47513232
--------------------------------------------------------------------------
        We're lying in the gutter, but we're looking at the stars.
--------------------------------------------------------------------------






More information about the thelist mailing list