problem with echoing this: echo("<input type="t

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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

problem with echoing this: echo("<input type="t

Post by nigma »

How can I use php's echo() to echo <input type="text" name="test">
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

you have to escape the " characters:

echo "<input type=\"button\" etc etc>";

use \ to escape " characters.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Thanks so much man.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Or you can put it into single quotes and not have to worry about escaping:

Code: Select all

echo '<input type="text" name="test">';
For more info:
http://www.php.net/manual/en/language.types.string.php

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

or even not use quotes for echo() ;)
User avatar
Sky
Forum Commoner
Posts: 71
Joined: Wed Oct 02, 2002 4:00 pm

Post by Sky »

Or put it like echo "<HTML STUFF='PROPERTY'....."; w or w/o ()'s
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Sky wrote:Or put it like echo "<HTML STUFF='PROPERTY'....."; w or w/o ()'s
No definitely don't do that - use double quotes around HTML attributes don't use single quotes.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

when there's a lot of static html text you want to output it might increase readability (and speed) if you leave the php-block and enter a new one afterwards, e.g.

Code: Select all

<html><body>
	<table>
<?php
$arr = array_map('sqrt', range(0,10));
foreach($arr as $num=>$sqrt)
{
?>
		<tr>
			<td><?php echo $num; ?></td>
			<td><?php echo $sqrt; ?></td>
		</tr>
<?php
}
?>
	</table>
</body></html>
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

You can also use...

Code: Select all

<?=$num?>
instead of...

Code: Select all

<? echo $code; ?>
Which is useful if you have a small piece of PHP output and a buttload of HTML.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

DeGauss wrote:You can also use...

Code: Select all

<?=$num?>
instead of...

Code: Select all

<? echo $code; ?>
Which is useful if you have a small piece of PHP output and a buttload of HTML.
Don't forget that you must have short tags enabled to use this method - this can be disabled.

Mac
Post Reply