Page 1 of 1

Php in div style

Posted: Thu Jun 10, 2010 5:18 am
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

Re: Php in div style

Posted: Thu Jun 10, 2010 5:56 am
by dejvos
Try this:

Code: Select all

<?php
echo '<div style="position: absolute; left:'.$width.'; top:'.$height.'; width: 1024px;">';
?>

Re: Php in div style

Posted: Thu Jun 10, 2010 6:45 am
by Dr Unk
Legend! Work perfectly thanks :D

Re: Php in div style

Posted: Thu Jun 10, 2010 7:37 am
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 :)