我有一个列表,包括寻找像这样的链接:我可以使用php包含xml文件中的元素吗?
<a href=index.php?p=page_1>Page 1</a>
<a href=index.php?p=page_2>Page 2</a>
<a href=index.php?p=page_3>Page 3</a>
当点击它们包括网页(page_1.inc.php或page_2.inc.php或page_3.inc.php)我的网页上感谢对此脚本:
<?php
$pages_dir = 'pages';
if(!empty($_GET['p'])){
$pages = scandir($pages_dir, 0);
unset($pages[0], $pages[1]);
$p = $_GET['p'];
if (in_array($p.'.inc.php', $pages)){
include ($pages_dir.'/'.$p.'.inc.php');
}
else {
echo 'Sorry, could not find the page!';
}
}
else {
include($pages_dir.'/home.inc.php');
}
?>
期间。
我也有一个XML文件看起来像这样:
<program>
<item>
<date>27/8</date>
<title>Page 1</title>
<info>This is info text</info>
</item>
<item>
<date>3/9</date>
<title>Page 2</title>
<info>This is info text again</info>
</item>
<item>
<date>10/9</date>
<title>Page 3</title>
<info>This just some info</info>
</item>
</program>
这就是我想要达到的目标:
如果我点击链接“1”,它会显示在“这是信息文本”上这一页。
如果我点击“页面2”链接,它会在页面上显示“这是信息文本”。
如果我点击链接“第3页”,它会在页面上显示“This just some info”。
我清楚了吗? 有没有解决方法?
是的,这是可能的。有一个简单的解决方案。如果没有人很快发帖,我会回到这个。 – cwallenpoole