Page 1 of 1

PHP syntax

Posted: Tue Nov 10, 2009 6:34 am
by Bob Kellock
I've had a fair amount of experience in programming in conventional languages such as C and Pascal but am a complete novice to PHP and am finding it quite difficult to get to grips with. For example it took me a couple of days to learn how to use session variables

There appears to be a dearth of very elementary information on the web and the book I bought is useless.

Some examples of what I need, or needed, to know are:
What is the difference, if any, between echo and echo()?
What is the syntax of arguments for print and echo?
What is the difference between \n and <br> in a print statement?
How do you embed a " in a string which is already within ""?
Under some circumstances "" or '' are interchangeable. What are those circumstances?
I used session_register("alpha"). Provided that I stuck to either $_SESSION[$alpha] or
$_SESSION['$alpha'] throughout my pages it worked OK. What effect, if any, do the 's have?

I'm not asking for answers (but wouldn't mind them) and appreciate that answers to individual questions can be found by tediously trawling the web.

Is there any website or book written by someone who doesn't presume that the reader has any knowledge of PHP but wants to understand its usage rather than hacking and hoping?

Bob

Re: PHP syntax

Posted: Tue Nov 10, 2009 8:34 am
by AbraCadaver
Bob Kellock wrote:I've had a fair amount of experience in programming in conventional languages such as C and Pascal but am a complete novice to PHP and am finding it quite difficult to get to grips with. For example it took me a couple of days to learn how to use session variables

There appears to be a dearth of very elementary information on the web and the book I bought is useless.

Some examples of what I need, or needed, to know are:
What is the difference, if any, between echo and echo()?
What is the syntax of arguments for print and echo?
What is the difference between \n and <br> in a print statement?
How do you embed a " in a string which is already within ""?
Under some circumstances "" or '' are interchangeable. What are those circumstances?
I used session_register("alpha"). Provided that I stuck to either $_SESSION[$alpha] or
$_SESSION['$alpha'] throughout my pages it worked OK. What effect, if any, do the 's have?

I'm not asking for answers (but wouldn't mind them) and appreciate that answers to individual questions can be found by tediously trawling the web.

Is there any website or book written by someone who doesn't presume that the reader has any knowledge of PHP but wants to understand its usage rather than hacking and hoping?

Bob
Every one of these are answered in the awesome documentation at php.net except maybe the \n vs. <br>. \n is a newline, <br> is a HTML tag telling the brower to render a newline. print("<br>"); will print <br> so if you view it in a brower it will appear to be a newline. print("\n") actually prints a newline so you'll see a newline in the view source or on the command line.

echo: http://us2.php.net/manual/en/function.echo.php
print: http://us2.php.net/manual/en/function.print.php
strings: http://us2.php.net/manual/en/language.types.string.php
sessions: http://us2.php.net/manual/en/book.session.php

-Shawn