simple quick question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
civrob
Forum Newbie
Posts: 1
Joined: Mon Jun 27, 2005 5:49 am

simple quick question

Post by civrob »

The following works perfectly

Code: Select all

<input name=&quote;&quote; type=&quote;submit&quote; value=&quote;<?= $company_name?>&quote;>
This does not? (closeses I get is)

Code: Select all

echo '<input name="" type="submit" value="' ,$company_name, '?>">';

I want to keep it all in php so when I come to do design in dreamweaver its just one block of code :-)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You escaped your single quotes when you didn't have to.

Code: Select all

echo "<input name=\"\" type=\"submit\" value=\"$company_name\">";

// or //

echo '<input name="" type="submit" value="$company_name">';
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Re: simple quick question

Post by harrisonad »

civrob wrote:

Code: Select all

echo '<input name="" type="submit" value="' ,$company_name, '?>">';
- replace commas with periods
- you don't have to put closing tag inside a string.

Code: Select all

echo '<input name="" type="submit" value="'.$company_name.'">';
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

why even escape the echo?
' . $var . ' could just easily be $var
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

scrotaye wrote:why even escape the echo?
' . $var . ' could just easily be $var
Not in single quotes like he/she's using here... it wont parse. Same goes for your second example...

It's a matter of preference hwo you do it but *most* editors won't highlight the variable is you don't concatenate it into the string.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I usually write it as following:

Code: Select all

echo "<input name='name' type='submit' value='{$company_name}">';
in this case { } is not needed, but as soon as you have a variable like $row['column'] you'll appreciate it ;)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

my Favorite.

Code: Select all

<input name="name" type="submit" value="<?php echo $company_name;?>">
Post Reply