在 PHP/HTML 中混合有序列表、链接和变量
我正在从 Project Euler 中休息一下,学习一些 PHP/HTML 来娱乐一下,我发现了一个页面简单的练习。因此,在我的“网站”上,我希望有一个指向每个练习页面的链接的有序列表,但我决定以动态方式进行,而不是在进行练习时对每个项目进行硬编码。不幸的是,应该包含该列表的页面根本没有呈现!
假设我的系统上有名称为“exawk#.php”的文件,这段代码还有什么问题?抱歉,如果它是马虎或可怕的,这实际上是我网络编程的第一天。
<html>
<head>
<title> Awaken's Exercises </title>
</head>
<body>
<h1>This page contains "Awaken's Exercises" from
<a href="http://forums.digitalpoint.com/showthread.php?t=642480">
this page</a>.</h1>
<ol>
<?php
$arex = glob("exawk*.php"); // $arex contains
//an array of matching files
$numex = 0;
$i = 0;
foreach( $arex )
{
$numex++;
}
while( $numex >= 0 )
{
echo "<li><a href=" .$arex[$i].
">Problem #" .$numex. ".</a></li>";
$numex--;
$i++;
}
?>
</ol>
</body>
</html>
I'm taking a break from Project Euler to learn some PHP/HTML for kicks and giggles, and I found a page of simple exercises. So, on my 'site,' I want to have an ordered list of links to pages of each of the exercises, but I decided to do it in a dynamic manner as opposed to hard coding each item as I do the exercise. Unfortunately, the page that should contain the list doesn't render at all!
Assuming I have files on my system with the names "exawk#.php," what else could be wrong with this code? Sorry if it is sloppy or horrible, it's literally my first day of web programming.
<html>
<head>
<title> Awaken's Exercises </title>
</head>
<body>
<h1>This page contains "Awaken's Exercises" from
<a href="http://forums.digitalpoint.com/showthread.php?t=642480">
this page</a>.</h1>
<ol>
<?php
$arex = glob("exawk*.php"); // $arex contains
//an array of matching files
$numex = 0;
$i = 0;
foreach( $arex )
{
$numex++;
}
while( $numex >= 0 )
{
echo "<li><a href=" .$arex[$i].
">Problem #" .$numex. ".</a></li>";
$numex--;
$i++;
}
?>
</ol>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 php.ini 中启用
display_errors
:foreach( $arex )
是语法错误(缺少.. as $varname
)。在命令行中,您可以使用 php -l /path/to/your/file.php 进行检查。
另外,这个示例:
可能是:
整个事情更好:
可能是:
Enable
display_errors
in php.ini:foreach( $arex )
is a syntax error (missing.. as $varname
).From the commandline, you could check it with
php -l /path/to/your/file.php
.Also, this sample:
Could be:
Better the whole thing:
Could be: