printing HTML

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
knmwt15000
Forum Newbie
Posts: 8
Joined: Thu Apr 25, 2002 9:51 am

printing HTML

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
knmwt15000
Forum Newbie
Posts: 8
Joined: Thu Apr 25, 2002 9:51 am

Post by knmwt15000 »

thanks, I did the \" it does exactly what I want.
User avatar
Friday
Forum Newbie
Posts: 5
Joined: Wed May 21, 2003 4:16 am
Location: China

Post by Friday »

Code: Select all

printf('<a href="test.php?id=%s">link</a>',$ID);
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply