1


我试图在我的 html 代码中使用 php 函数,但它一直将此块视为注释!(源代码中的颜色为绿色,不输出任何内容)尽管我在另一个文件中使用了相同的函数,即使在 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();

?>

正在使用的 html 文件是我在网上找到的模板……对我应该检查的内容有什么建议吗?
谢谢!

4

3 回答 3

2

关于您粘贴的代码的一些事情:

  1. function x ()也必须在里面<?php?>标签被视为 php 代码。

  2. 您的函数 x()没有返回任何内容,因此您需要将其称为 asx();而不是 asecho x();

于 2011-03-27T20:41:47.373 回答
2

这将使它起作用:

<?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.

?>

这是一个稍微好一点的版本:

<?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');

?>
于 2011-03-27T20:50:20.237 回答
0

函数本身需要包装在标签中

于 2011-03-27T20:35:20.357 回答