如何在html中输入php值?
上述代码用于获取页面url。。 现在我想从上面的代码中得到一个html代码如何在html中输入php值?,php,html,Php,Html,上述代码用于获取页面url。。 现在我想从上面的代码中得到一个html代码 <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERV
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
谢谢..您需要首先调用函数,并将其结果存储在变量中。您可以在html中使用该变量 例如:
<?php
$r .= '<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="I WANT THE ANSWER IN HERE" num_posts="2" width="400"></fb:comments>';
?>
<?php
$result = curPageUrl();
?>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="<?php echo $result; ?>" num_posts="2" width="400"></fb:comments>
您不需要在输出中添加额外的
标记,而且在开口之间有一个空间,您可以这样做:
<?php
$r .= '<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="'.$pageURL.'" num_posts="2" width="400"></fb:comments>';
?>
试试这个:
<?php
$r .= '<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="'.curPageURL().'" num_posts="2" width="400"></fb:comments>';
//echo $r;
?>
PHP\u EOL
可以确保文档中出现换行符(如果单击“查看源代码”(view source)可以使文档更具可读性)。我这样做了,但不起作用……我认为这是因为html代码在php代码中。你有其他方法吗?@Navi,我用另一种方法编辑了我的原始答案,你可以尝试。你大部分时间都在HTML中,然后只在需要调用函数时才进入PHP。伙计们非常感谢你的帮助。我真的很感谢你。非常感谢。增加了一点额外的(PHP_EOL)。很高兴能够提供帮助。不,不应该,因为您正在设置一个变量。请注意,我是如何删除单引号并再次添加到变量result中的。
<?php
$r .= '<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="'.curPageURL().'" num_posts="2" width="400"></fb:comments>';
//echo $r;
?>
<?php
$r = '<div id="fb-root"></div>'. PHP_EOL;
$r .='<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>'. PHP_EOL;
$r .='<fb:comments href="'.curPageURL().'" num_posts="2" width="400"></fb:comments>'. PHP_EOL;
echo $r;
?>