PHP syntax

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bob Kellock
Forum Newbie
Posts: 10
Joined: Fri Oct 30, 2009 10:57 am
Location: Wiltshire, UK

PHP syntax

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP syntax

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply