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


Where to Learn the Correct Syntax for php





Possum
Hi

I am playing around with php and have found that

<?php include 'menu.php'; ?>


works just like


<?php include ('menu.php'); ?>


or

<?php include ("menu.php"); ?>



What is the best way to do this..

Is there a place I can learn about the correct use of php syntax


thx......

P.S... I live on http://php.net/manual
rx9876
php code is not so restricted, so there is some trick.

<?php include ('menu.php'); ?>
<?php include ("menu.php"); ?>
In common sense, single quote is faster than double quote,
because php engine treats double quote string as a object which might be used later.

Maybe referencing to some framework library will help you, for example zend or ci.
Peterssidan
Single quotes is faster because it keeps all characters in the string as-is. With double quotes it translates escape sequences like \n and \t into special characters and expands variables names.
Example:
Code:
$name = "Peter";
$age = 24;
echo "Hello my name is $name and I'm $age years old.";
This will print: Hello my name is Peter and I'm 24 years old.

You can read more about the difference between double and single quoted string literals here
http://php.net/manual/en/language.types.string.php
Possum
thx everyone..

Yes Peterssidan I seem to remember that. Its all coming together...
manfer
<?php include 'menu.php'; ?>

would be preferable than

<?php include ('menu.php'); ?>

because you have to write less. The parenthesis are not needed because include is not a function but a language construct like require or echo for example.
sonam
I am using single or double quotes independent am I need to include variable in include line or not. Single quotes is strict and double quotes are less strict. For example:

This will work:
Code:
$url = 'some_url.php'; // variable
include ("http://my_hosting.com/$url");


This will not work:
Code:
$url = 'some_url.php';
include ('http://my_hosting.com/$url');


If you are using single quotes and variable then you need to separate variable from quotes:
This will work:
Code:
$url = 'some_url.php';
include ('http://my_hosting.com/' . $url);


Sonam
nathanadhitya
Try Learning somewhere like W3Schools.com
codersfriend
You can try your php syntax in http://codepad.org/. It's an online php interpreter.. you can enter your php tags there.. just include <?php .. you can also use it as a pastebin
Possum
Thx codersfriend

Codepad very cool and useful
Related topics
a site where i can learn mysql syntax
how did you learn about html, php or other languages???
Browser Compatibility issues
Where to install a phpBB forum?
PHP VS ASP
where i put my PHP file
where to install php?
I'd like to learn PHP and MySQL
where to start in php
Downtime on Server 2/3 today
python (django) or php
PHP and MySQL server on Android
SQL Basics
Using PHP
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.