PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1847
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
PHP Syntax Posted by rodkreker on 20 Jan 2010 at 10:38 AM
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.
Report
Re: PHP Syntax Posted by moofoo on 20 Jan 2010 at 1:44 PM
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:
if (foo){
    echo'bar';
}else{
     echo'foo';}

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:
function foobar($foo, $bar)
{
     if($foo == $bar){
          $foobar = true;
          return $foobar;
     }else{
          $foobar = false;
          return $foobar;}
}

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:
echo'hello world';

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.
$world = 'world';
echo'hello ' . $world;

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:
$world = 'world';
echo"hello $world";

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
Report
Re: PHP Syntax Posted by rodkreker on 20 Jan 2010 at 11:57 PM
Thank you moofoo i appreciate your help. thanks much!
Report
Re: PHP Syntax Posted by langdon4487 on 4 Feb 2010 at 5:06 AM
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


Report
Re: PHP Syntax Posted by 1337N00B on 20 Jan 2010 at 3:10 PM
Report
Re: PHP Syntax Posted by rodkreker on 20 Jan 2010 at 11:55 PM
Thanks very much 1337noob. This is the kind of site im lookin for. Thanks!
Report
Re: PHP Syntax Posted by Jeremi on 15 Feb 2010 at 8:49 AM
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 php tutorials sends the text “Conkurent LLC” to the browser:
<html>
 
<body>
 
<?php
 
echo " Conkurent LLC";
 
?>
 
</body>
 
</html>
 
To make a single-line comment, use //. To make a large comment block, use  /* and */. See the example below:
 
<html>
 
<body>
 
<?php
 
//This is a comment
 
/*
 
This is
 
a comment
 
block
 
*/
 
?>
 
</body>
 
</html> 


Report
Re: PHP Syntax Posted by david_jane on 23 Feb 2011 at 8:28 AM
Visit this : widely discussed
http://www.w3resource.com/php/syntax/syntax.php



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.