如何使用包含文件中父文件中声明的php变量 [英] How use a php variable declared in the parent file in an included file
本文介绍了如何使用包含文件中父文件中声明的php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将php变量 $ shareURL =someURL;
从test.php的父页面传递到commentTest.php的包含文件中。这可能吗?如果是,请帮助。
I'm trying to pass the php variable $shareURL = "someURL";
from the parent page of test.php into the included file of commentTest.php. Is this possible? If yes, please help.
父文件= Test.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
$shareURL = "someURL";
echo "$shareURL";
include "http://domainName.net/assets/includes/commentTest.php";
?>
</body>
</html>
包含PHP的文件= commentTest.php
<?PHP
echo "<div class='fb-comments' data-href='$shareURL' data-num-posts='5' data-width='100%'></div>";
?>
HTML输出源
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
someURL<div class='fb-comments' data-href='' data-num-posts='5' data-width='100%'></div></body>
</html>
推荐答案
谢谢大家!
您的意见和答案帮助我找到了我需要的解决方案。
Your comments and answers helped me find the solution I needed.
$root = dirname(__FILE__);
include "$root/assets/includes/commentTest.php";
显然我的根在这里 / var / www / html
而不是在URL中的TLD之后。
Apparently my root is here /var/www/html
instead of right after the TLD in the URL.
这篇关于如何使用包含文件中父文件中声明的php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文