Page 1 of 1

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

Posted: Sun Jan 26, 2003 7:46 pm
by nigma
How can I use php's echo() to echo <input type="text" name="test">

Posted: Sun Jan 26, 2003 7:48 pm
by evilcoder
you have to escape the " characters:

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

use \ to escape " characters.

Posted: Sun Jan 26, 2003 8:25 pm
by nigma
Thanks so much man.

Posted: Mon Jan 27, 2003 2:18 am
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

Posted: Mon Jan 27, 2003 2:20 am
by m3mn0n
or even not use quotes for echo() ;)

Posted: Sun Feb 02, 2003 11:22 pm
by Sky
Or put it like echo "<HTML STUFF='PROPERTY'....."; w or w/o ()'s

Posted: Mon Feb 03, 2003 2:49 am
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

Posted: Mon Feb 03, 2003 7:01 am
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>

Posted: Mon Feb 03, 2003 7:45 am
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.

Posted: Mon Feb 03, 2003 7:52 am
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