Page 1 of 1

printing HTML

Posted: Wed May 21, 2003 2:59 am
by knmwt15000
Hi,

when doing loop output statements using data from mysql and i'm printing html I have to do attribute values without quote marks, the php confuses them with ones in its own code. I know you can do attributes without quotes but this is not good html. Is there a way around this?

I tried using the & quote ; (without spaces) but this does not work inside html elements.

Posted: Wed May 21, 2003 3:08 am
by twigletmac
Have a read of:
http://www.php.net/manual/en/language.types.string.php

Basically, you can do:

Code: Select all

echo '<a href="test.php?id='.$ID.'">link</a>';
or

Code: Select all

echo "<a href="test.php?id=$ID">link</a>"
or

Code: Select all

echo <<<END
<a href="test.php?id=$ID">link</a>
END;
or exit out of the PHP and do the HTML that way.

Mac

Posted: Wed May 21, 2003 3:22 am
by knmwt15000
thanks, I did the \" it does exactly what I want.

Posted: Wed May 21, 2003 4:16 am
by Friday

Code: Select all

printf('<a href="test.php?id=%s">link</a>',$ID);

Posted: Wed May 21, 2003 7:16 am
by twigletmac
Friday wrote:

Code: Select all

printf('<a href="test.php?id=%s">link</a>',$ID);
Don't use printf() unless you need to format the output - used as it is above it's fairly redundant.

Mac