FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[Beginner] Echoing





yimaw
Depending on how you echo you'll have to escape different characters. This just gives a run down of the echo statement, enjoy.

echo ""; #double quotes
and
echo ''; #single quotes

I personally like the second one with single quotes, but they each really have their purpose...

echo "$variable";
echo '$variable';

The first one will echo what's inside the variable.
The second one will echo the word "$variable"

The (.) period or the (,) comma can be used to stick variables and strings together.

Such as...
echo 'Hi '.$momname.' how are you doing?<br />';
or
echo 'Hi ',$momname,' how are you doing?<br />';
or
echo "Hi $momname how are you doing?<br />";

There are sometimes when you really would be better off using single quotes and sometimes double. I'm anal when it comes to it and like my single quotes because they look trendy.

Either way though you have to escape the type of quotes you use on the outside.

To escape a single quote \'
To escape a double quote \"

For example,
echo 'Hi there, what's your name?';
That will result in a syntax error...
echo 'Hi there, what\'s your name?';
Is the correct way to do it.

echo 'He called her, "The bomb."';
No syntax error because on the outside we're using single quotes.

echo "He called her, "The bomb."";
Syntax error, see the double quotes on the outside?

echo "He called her, \"The bomb.\"";
No syntax error.


One final example,

She's really one of those, "Valley Girls."
echo 'She\'s really one of those, "Valley Girls."';
echo "She's really one of those, \"Valley Girls.\";
Related topics
What is your operating system?
Ok a little help for a semi-beginner
Math Joke
Tieskevo's DESIGNING FAQ 1
[Beginner] css rollovers
[beginner] CSS Font property :
[Beginner] Classes, Applying classes in CSS
would this be hard to do
Contact form
Adobe audition
beginner in Web World
Language to learn for beginner
a good book for learning html for beginner
I'm Beginner. What framework or preprocessor for CSS3?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.