Page 1 of 1

simple quick question

Posted: Mon Jun 27, 2005 5:56 am
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 :-)

Posted: Mon Jun 27, 2005 6:01 am
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">';

Re: simple quick question

Posted: Mon Jun 27, 2005 6:15 am
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.'">';

Posted: Mon Jun 27, 2005 7:03 am
by s.dot
why even escape the echo?
' . $var . ' could just easily be $var

Posted: Mon Jun 27, 2005 7:11 am
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.

Posted: Mon Jun 27, 2005 9:20 am
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 ;)

Posted: Mon Jun 27, 2005 11:40 am
by ol4pr0
my Favorite.

Code: Select all

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