Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PHP Syntax

rodkrekerrodkreker Posts: 5Member
Heya guys,

I'm trying hard to learn php at home. I got this book thing (Apress - PHP for Absolute Bigenners 2009). As I go through it and reached script writing, I realized that I still don't know the definitions/meanings of each terms, symbols and syntax that PHP uses for script writing like for example the ('), ("), ({}) and some other stuff used to construct a script. I hope I can read from you guys, the only experience I have in programming before is Turbo Pascal. I do apologize for this silly question. I can't find any PHP syntax dictionary online, do I need to practice another language before getting to PHP or something? I hope you guys understand what I'm trying to say, I don't know the right word to use.

Thank you for replying. God Bless.

Comments

  • moofoomoofoo Posts: 1Member
    I hope this helps, I am fairly new to php myself, but have figured out a lot of it. The curly brackets. i.e. {}, are used to delimit parts of your code. They mark starting and stopping points for actions in if then statements.
    example:
    [code]
    if (foo){
    echo'bar';
    }else{
    echo'foo';}
    [/code]
    So in this sense it is used thusly if some condition is met, then some action must be followed, and that action is the code contained in the curly brackets, if that condition is not met then the action is the code in the curly brackets below the else statement.
    Another use of the curly brackets is to delimit functions.
    example:
    [code]
    function foobar($foo, $bar)
    {
    if($foo == $bar){
    $foobar = true;
    return $foobar;
    }else{
    $foobar = false;
    return $foobar;}
    }
    [/code]
    There you see a simple function that you can call to tell if two variables are equal or not. Obviously more indepth checks can be done, but this shows how the curly brackets are mainly used.
    As for the single and double quotes those are quite useful.
    Single quotes mark the beginning and end of a pure string. they can be used like this
    example:
    [code]
    echo'hello world';
    [/code]
    No php parsing is done to strings contained in a set of single quotes, so you must concatenate with a period to include variables into the echo function like this.
    [code]
    $world = 'world';
    echo'hello ' . $world;
    [/code]
    The result would be the same, as the previous echo statement.
    Lastly I get to the double quotes, double quotes denote a string with php variables in it. Therefore you can take the previous script and modify it like this
    example:
    [code]
    $world = 'world';
    echo"hello $world";
    [/code]
    This works because the double quotes indicate that php needs to parse the string before it is used. However it should be noted that this is more system intensive than concatenation and is useful, but be careful.
    I hope this helps :)
    Sincerley
    Moo
  • rodkrekerrodkreker Posts: 5Member
    Thanks very much 1337noob. This is the kind of site im lookin for. Thanks!
  • rodkrekerrodkreker Posts: 5Member
    Thank you moofoo i appreciate your help. thanks much!
  • langdon4487langdon4487 Posts: 1Member
    Hello all...
    If you are using a single statement in if or else condition then there is no need to put a curly braces({}).
    They make no sense for the single statement..
    It works similarly without curly braces.

    Thanks and Regards.

    ---------------------------
    ClickSSL.com


  • JeremiJeremi Posts: 1Member
    PHP code is executed on the server, and the plain HTML result is sent to the browser. A PHP scripting block can be placed anywhere in the document. It always starts with <?php and ends with ?>.
    The example of PHP code from [link=http://phpforms.net/tutorial.html]php tutorials[/link] sends the text
Sign In or Register to comment.