开发者

PHP block in HTML code

am trying to use a php function within my html code but it keeps treating this block as a comment!(colored green in the source and not outputting anything) though i used the same function 开发者_开发技巧in another file and it worked just fine even within html...

function x (){
$x = 'hello';

echo('<marquee direction="left" scrollamount="3" behavior="scroll" style="width:300px;

height: 15px; font-size: 11px;">');

echo $x;

echo'</marquee>';

}


<?php

echo x();

?>

The html file am using is a template i found online...any suggestions for what i should be checking?

Thanks!


Here's what will make that work:

<?php

function x (){
$x = 'hello';

echo('<marquee direction="left" scrollamount="3" behavior="scroll" style="width:300px;

height: 15px; font-size: 11px;">');

echo $x;

echo'</marquee>';

}



x(); // Not echo, because the function doesn't return a value.

?>

Here's a slightly nicer version:

<?php

function x ($message){

$html = '<marquee direction="left" scrollamount="3" behavior="scroll" style="width:300px; height: 15px; font-size: 11px;">'.$message.'</marquee>';

return $html;

}



echo x('hello');

?>


Coupe of things about the code you pasted:

  1. function x () must also be inside <?php and ?> tags to be treated as php code.

  2. Your function x() is NOT returning anything so you need to call it as x(); and not as echo x();


The function itself needs to be wrapper in the tags

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜