My first PHP script :)

Symbian.Ankit

New Member
Messages
12
Reaction score
0
Points
0
Hi all

I am a newbie to learning php but will complete it soon:biggrin:
I am learning from SAMS TEACH YOURSELF PHP IN 10 MINUTES + Programmers Introduction to php4.

I hope you will help me all:lockd:

Thanks in advance

So here is my first php script.Please point out the mistakes if any

<html>
<body>
<?php
echo today date is ('j H Y');
echo and time is;
echo ('H:i:s');
?>
</body>
</html>


Can anyone tell me the difference between single quoted(' ') and double quoted strings (" ").Please help me.
 

kajasweb

New Member
Messages
1,723
Reaction score
0
Points
0
The code must be
Code:
<html>
<body>
<?php
echo "today date is " . date('j H Y');
echo "and time is";
echo date('H:i:s');
?>
</body>
</html>

I think... Single quotes and double quotes are just same. But, they can't be mixed.
 
Last edited:

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
Good book for learning PHP but check for PHP 5.
 

DarkDragonLord

New Member
Messages
782
Reaction score
0
Points
0
Better you start learning PHP5, since 4 is already out dated and soon they will release PHP6.

Btw, dunno where i read that but, i think double quotes are more strict... o_O~ Well, i always use double quotes ... just single when is to parse something, like $_GET['blablabla']
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
You must use single ' if the sentence contains a " and " if it contains ' if you don't escape them. I suggest escaping such things. Otherwise I don't think there is any differens
 

mmyers

New Member
Messages
7
Reaction score
0
Points
0
For your example, there's no significant difference, but when you're working with variables in php there is.

PHP evaluates variables enclosed in double quotes:

<?php
$thing="this car";

echo "I need to buy $thing.";
?>
Displays: I need to buy this car.

When you use single quotes, the variable isn't evaluated:
<?php
$thing="this car";

echo 'I need to buy $thing.';
?>
Displays: I need to buy $thing.

Cheers and good luck with your work.
 

Franc0

New Member
Messages
206
Reaction score
0
Points
0
double quates are literal.. for example..


echo date('H:i:s'); WILL DISPLAY DATE IN THAT FORMAT

echo date("H:i:s"); WILL LITERALLY DISPLAY "H:i:s"
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
PHP 5.3 is coming before PHP 6, 5.3 will introduce new features coming in PHP6. You might want to wait a bit before learning;).
 

oiwio

New Member
Messages
214
Reaction score
0
Points
0
also, when having a variable = another variable, you dont need quotes as long as its that variable itself or +, -, *, or / by a number
 

port5900

New Member
Messages
150
Reaction score
0
Points
0
PHP 5.3 is coming before PHP 6, 5.3 will introduce new features coming in PHP6. You might want to wait a bit before learning
Why? the fundamentals are the same across all versions of PHP.
 
Top