注意:到目前为止,我已阅读了大约25个与此有关的问题,但从未直接回答如何正确使用这些变量的问题.如果它听起来像重复,我道歉.
我正在重写一个扁平的电子商务网站(所有手工制作的.htm文件!),以便使用PHP脚本生成一些页面.这一切只是为了让我的生活更轻松.我曾多次告诉我的老板,这个网站需要从轨道上进行核查,并且还有一个完整的CMS正在筹备中.与此同时,这个网站需要进行改造.有问题的网站:http://www.leather.com
我一直在使用constructor_page.php该声明并初始化几个变量,如$itemName和$imagePath那些在使用include()"d内容页面(例如修剪如下):
<?php
$imagePath = 'http://leather.com/images/harley_leather_boots/d81024_ladies_harley_leather_boots_360.jpg';
$itemName = 'Faded Glory Harley Boots';
include 'library/content.php'; //this in turn includes more files like the nav bar
?>
Run Code Online (Sandbox Code Playgroud)
这样我只需保存constructor_page.php为有问题的项目页面,修改一些变量,然后include()语句处理其余部分.这部分工作正常.
我的问题是从同一目录中的文件自动生成"部门"页面.我希望index.php在循环中获取相同的变量:
<?php
foreach (glob("*.php") as $filename) {
include $filename;
echo '<div class="related">';
echo '<a href="';
echo $filename;
echo '">';
echo '<img src="';
echo $imagePath;
echo '" alt="';
echo $imageAlternateText;
echo '" class="frame-related align-left-related"';
echo '></a>';
echo …Run Code Online (Sandbox Code Playgroud) php ×1