Old 08-04-2004   #1 (permalink)
Red Dawn
 
BlodoPKNZ's Avatar
 
Join Date: May 2004
Location: Eastern Europe
Posts: 302

PHP Syntax question

Very noob question but i just cant seem to find an answer for it. How to print a variable between text in the browser.

like:
PHP Code:
$day 'monday';
echo 
'today is' $day 'and im going to town'
Obviously that wont work, but what will then?
__________________
BlodoPKNZ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #2 (permalink)
Registered User
 
Join Date: Jun 2004
Posts: 90

Can't you do this?

PHP Code:
$day 'monday'
echo(
"today is $day and im going to town"); 
jonbalza is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #3 (permalink)
Red Dawn
 
BlodoPKNZ's Avatar
 
Join Date: May 2004
Location: Eastern Europe
Posts: 302

Nope coz it will output $day as text not reading the var.
__________________
BlodoPKNZ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #4 (permalink)
Registered User
 
Join Date: Jun 2004
Posts: 90

OK, then do this:

PHP Code:
$day 'monday'
echo 
"today is " $day " and im going to town"
The . operator is the concatenation method for PHP.
jonbalza is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #5 (permalink)
Red Dawn
 
BlodoPKNZ's Avatar
 
Join Date: May 2004
Location: Eastern Europe
Posts: 302

Sorry im an idiot. Your previous method worked i just forgot to delete a semicolon

Well thanks anyway.
__________________

Last edited by BlodoPKNZ; 08-04-2004 at 06:21 PM.
BlodoPKNZ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #6 (permalink)
Registered User
 
Join Date: Jun 2004
Posts: 90

Glad I could help.
jonbalza is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #7 (permalink)
ahmedtheking
Guest
 
Posts: n/a

instead of that, u could

$varible = 'whatever';
print ('hello, $varible');

and/or

echo 'hello, $varible';

but always remeber the ;
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-04-2004   #8 (permalink)
Red Dawn
 
BlodoPKNZ's Avatar
 
Join Date: May 2004
Location: Eastern Europe
Posts: 302

I know about the " ; " but php is so syntax sensitive that i get frustrated sometimes Anyways i needed that for a super simple image gallery script
PHP Code:
<?php $name $_GET['name'];
echo 
"<img src=shots/$name.jpg>";
?>
It works now so i guess next thing will be ill try to expand it hehe
__________________
BlodoPKNZ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-07-2004   #9 (permalink)
Local Biorust Beast
 
Order's Avatar
 
Join Date: Oct 2003
Location: San Diego, CA, USA
Posts: 2,253

Send a message via AIM to Order Send a message via MSN to Order Send a message via Yahoo to Order
first off, here is the rule on "" and '' in php.

" and " should be used where you have vars in there, if possible, use . to keep var seperate from strings as much as possible. " and " take more processing times since they check for vars inside them. This method is taught the most, but is the wrong way of doing things.

' and ' do not check for vars, and will speed your script up nicely, and it is also good coding habit. Use . to keep vars seperate.

Either way works, just the little differences in them.
__________________
Order is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-08-2004   #10 (permalink)
Red Dawn
 
BlodoPKNZ's Avatar
 
Join Date: May 2004
Location: Eastern Europe
Posts: 302

Thanks Order, thats worth remembering
__________________
BlodoPKNZ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 11:51 AM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT