Php in div style

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
Dr Unk
Forum Newbie
Posts: 2
Joined: Thu Jun 10, 2010 5:16 am

Php in div style

Post by Dr Unk »

Can anyone see where im going wrong with the following code? I get this error

[text]Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /disks/diskh/zco/codrb/public_html/form.php on line 45[/text]

Code: Select all

echo'<div style="position: absolute; left:'$width'; top:'$height'; width: 1024px;">';
the variables height and width are in the from 1024px

Thanks

Dunk
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: Php in div style

Post by dejvos »

Try this:

Code: Select all

<?php
echo '<div style="position: absolute; left:'.$width.'; top:'.$height.'; width: 1024px;">';
?>
Dr Unk
Forum Newbie
Posts: 2
Joined: Thu Jun 10, 2010 5:16 am

Re: Php in div style

Post by Dr Unk »

Legend! Work perfectly thanks :D
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Php in div style

Post by Apollo »

Reason: PHP variables are only evaluated inside strings quoted with double quotes. So if you would use " instead of ' (and then ' or \" instead of " inside the string, for the quotes around the style property) it would have worked :)
Post Reply