Click here to get back home

echo format Q

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
echo format Q Twayne 07-03-2008
|--> Re: echo format Q Michael Fesser07-04-2008
Get Chitika Premium
Posted by Twayne on July 4, 2008, 1:16 pm
Please log in for more thread options
> Twayne wrote:
>> Hi,
>>
>> Irrelevant question time, probably:
>>
>> Is there any advantage/reason to use one format over the other for
>> the following two types of echo statements?
>>
>> 1. echo "error is " . $error;
>> 2. echo "error is $error";
>>

...

>> ... Mostly, so that I pick up the
>> preferred habit if nothing else.
>>
>> TIA,
>>
>> Twayne
>
> Rather than
> 2. echo "error is $error";
>
> you should get used to using:
> 2. echo "error is ";
>
> And
> 1. echo "error is " . $error;
>
> is better as:
> 1. echo 'error is ' . $error;



OHHHHHhhh, now you've gone and done it! I told myself I'd not get into
that one yet as it was going to make me look even stupider (is that a
word?<g>) than I've already made myself look! :^)

OK, I understand:
-- Curly braces define begin/end and thus helps avoid spaces etc.;
extends a line to multiple lines; keeps things related to each other;
and in my case still confuse me;
-- because, although I understand echo "error is ";
, I do NOT clearly understand, taking a different sample of, for
instance:
echo "He drank some s";
All the explanations note that 's' is a valid character for variable
names, but ... so what? If $beers='beers', then, OH! ... Are these
examples trying to say that one cannot make a var plural of, say,
$beer='beer' by simply adding the "s" to it? Is THAT what it's
trying to point out? Boy, if that's the case, they do a lousy job of
it! <g>.

I considered deleting the foregoing and rewording it, then decided
against deleting it so you can see where my head is.

Is the following correct?
IF $beer = 'beer'
then printing/echoing "beers" is s, and NOT $beers ;
correct? That seems suspicious to me because I can't see why anyone
would try to do it the wrong way in that case. So though I'm not
comfortable with that interpretation right now, it's the only one that
seems to make sense to me.

If that's not the case then I'm still lost: Net.php, w3schools and
several tuts all seem to copy each other and explain this part in the
same way.

So if I'm wrong, then can you explain a differenct significance of
the "s" in the examples?

I've even seen other forums where they talk about being sure they
didn't use an "s" and still don't understand why something didn't work.
They seem to talk about "s" as though it's some
super-secret-reserved-word or something and for whatever reason never
mention any other letter. But it doesn't make sense to me that way
either.

lol, if I haven't made a completely *clear's mud* post out of this, any
clarification/verification would be most appreciated.
Also, if you were just trying to confuse me with (['(s'])), then
_shame_ on you<g>! Yeah yeah, I know, all newbies have to pay their
dues, but ... .

TIA,

Twayne



Posted by Michael Fesser on July 4, 2008, 6:58 pm
Please log in for more thread options
.oO(Twayne)

>[...]
>
>Once more, thanks for your time & patience, & best regards,

You're welcome.

Micha

Posted by Norman Peelman on July 6, 2008, 11:02 am
Please log in for more thread options
Twayne wrote:
>> Twayne wrote:
>>> Hi,
>>>
>>> Irrelevant question time, probably:
>>>
>>> Is there any advantage/reason to use one format over the other for
>>> the following two types of echo statements?
>>>
>>> 1. echo "error is " . $error;
>>> 2. echo "error is $error";
>>>
>
> ...
>
>>> ... Mostly, so that I pick up the
>>> preferred habit if nothing else.
>>>
>>> TIA,
>>>
>>> Twayne
>> Rather than
>> 2. echo "error is $error";
>>
>> you should get used to using:
>> 2. echo "error is ";
>>
>> And
>> 1. echo "error is " . $error;
>>
>> is better as:
>> 1. echo 'error is ' . $error;
>
>
>
> OHHHHHhhh, now you've gone and done it! I told myself I'd not get into
> that one yet as it was going to make me look even stupider (is that a
> word?<g>) than I've already made myself look! :^)
>
> OK, I understand:
> -- Curly braces define begin/end and thus helps avoid spaces etc.;
> extends a line to multiple lines; keeps things related to each other;
> and in my case still confuse me;
> -- because, although I understand echo "error is ";
> , I do NOT clearly understand, taking a different sample of, for
> instance:
> echo "He drank some s";
> All the explanations note that 's' is a valid character for variable
> names, but ... so what? If $beers='beers', then, OH! ... Are these
> examples trying to say that one cannot make a var plural of, say,
> $beer='beer' by simply adding the "s" to it? Is THAT what it's
> trying to point out? Boy, if that's the case, they do a lousy job of
> it! <g>.
>
> I considered deleting the foregoing and rewording it, then decided
> against deleting it so you can see where my head is.
>
> Is the following correct?
> IF $beer = 'beer'
> then printing/echoing "beers" is s, and NOT $beers ;
> correct? That seems suspicious to me because I can't see why anyone
> would try to do it the wrong way in that case. So though I'm not
> comfortable with that interpretation right now, it's the only one that
> seems to make sense to me.
>
> If that's not the case then I'm still lost: Net.php, w3schools and
> several tuts all seem to copy each other and explain this part in the
> same way.
>
> So if I'm wrong, then can you explain a differenct significance of
> the "s" in the examples?
>
> I've even seen other forums where they talk about being sure they
> didn't use an "s" and still don't understand why something didn't work.
> They seem to talk about "s" as though it's some
> super-secret-reserved-word or something and for whatever reason never
> mention any other letter. But it doesn't make sense to me that way
> either.
>
> lol, if I haven't made a completely *clear's mud* post out of this, any
> clarification/verification would be most appreciated.
> Also, if you were just trying to confuse me with (['(s'])), then
> _shame_ on you<g>! Yeah yeah, I know, all newbies have to pay their
> dues, but ... .
>
> TIA,
>
> Twayne
>
>

Just keep in mind that the curly braces isolate variables from the
rest of the string, and if not using concatenation '.' are required in
certain circumstances:

$array['car']['make']['color'] = 'silver';

echo "Joe drives a $array['car']['make']['color'] car."; //doesn't work
echo "Joe drives a $array[car][make][color] car."; //doesn't work

echo "Joe drives a car."; //works

Points to remember:

Single quotes around array keys are not needed when the array variable
is embedded inside double quoted string. But they are required when
using curly braces to isolate the variable.

Single quotes around array key names are required inside curly braces.

Curly braces are required around multi-dimensional arrays.



--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

Posted by Twayne on July 6, 2008, 1:08 pm
Please log in for more thread options
...
>
> Just keep in mind that the curly braces isolate variables from the
> rest of the string, and if not using concatenation '.' are required in
> certain circumstances:
>
> $array['car']['make']['color'] = 'silver';
>
> echo "Joe drives a $array['car']['make']['color'] car."; //doesn't
> work echo "Joe drives a $array[car][make][color] car."; //doesn't work
>
> echo "Joe drives a car."; //works
>
> Points to remember:
>
> Single quotes around array keys are not needed when the array variable
> is embedded inside double quoted string. But they are required when
> using curly braces to isolate the variable.
>
> Single quotes around array key names are required inside curly braces.
>
> Curly braces are required around multi-dimensional arrays.


Hmm, that's wording I can remember and good clarification that's worthy
of my lists too.

Thanks, Norman

Twayne




Similar ThreadsPosted
echo all the time vs echo at the end - what is faster November 5, 2005, 9:23 am
XML Format help April 2, 2008, 8:59 pm
Date format March 12, 2005, 6:48 pm
PHP documentation in pdf format? May 10, 2005, 10:43 pm
Format float May 14, 2006, 8:51 am
year in a (****) format March 27, 2007, 2:51 pm
How to format a date? January 14, 2008, 6:28 pm
DATE Format March 25, 2008, 6:28 am
PHP / MySQL time format February 16, 2005, 1:14 am
Export Results in XML Format March 17, 2005, 9:42 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap