代码如下(文中调用的HTML 文件在php代码之后):
<html>
<head>
<title>Stock exchange check</title>
</head>
<body>
<h1>Amazon's stock current price</h1>
<?php$symbol='AMZN';
echo '<h1>Stock quote for'.$symbol.'</h1>'; $theurl="quotetest.html"; if (!($content=file_get_contents($theurl))) {
echo("the url is not existed. please try later");
exit;
}$pattern='(\\$[0-9]+\\.[0-9]+)';
echo $pattern;
$quote=array();
if (eregi($pattern,$content,$quote)) {
echo '<p>stock last sold at:';
echo $quote[1];
echo '</p>';}
else {
echo '<p> No quote available</p>';
};echo '<p>'
.'this information retrieved from <br/>'
."<a href=\"$theurl\">$theurl</a><br />"
.'on'.(date('l jS F Y g:i a T ')).'</p>';
echo '<p>'
.'This information retrieved from <br />'
."<a href=\"$theurl\">$theurl</a><br />"
.'on '.(date('l jS F Y g:i a T')).'</p>';
?>
</body>
</html>
以下是HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>price test</h1>
<p>this $42.56is a price $26.28 test, we will list of tests</p>
<ul>
<li>$5386.235</li>
<li>$42.56</li>
<li>$65.23</li>
<li>$15.25</li>
<li>$28.23</li>
<li>$42.56</li>
<li>$45.23</li></ul>
</body>
</html>
我的问题是, 为什么eregi取出的数组$quote只有两个相同的值,但是html文件中还有很多跟pattern相同的变量,那位高手能解释一下?谢谢 :)
<html>
<head>
<title>Stock exchange check</title>
</head>
<body>
<h1>Amazon's stock current price</h1>
<?php$symbol='AMZN';
echo '<h1>Stock quote for'.$symbol.'</h1>'; $theurl="quotetest.html"; if (!($content=file_get_contents($theurl))) {
echo("the url is not existed. please try later");
exit;
}$pattern='(\\$[0-9]+\\.[0-9]+)';
echo $pattern;
$quote=array();
if (eregi($pattern,$content,$quote)) {
echo '<p>stock last sold at:';
echo $quote[1];
echo '</p>';}
else {
echo '<p> No quote available</p>';
};echo '<p>'
.'this information retrieved from <br/>'
."<a href=\"$theurl\">$theurl</a><br />"
.'on'.(date('l jS F Y g:i a T ')).'</p>';
echo '<p>'
.'This information retrieved from <br />'
."<a href=\"$theurl\">$theurl</a><br />"
.'on '.(date('l jS F Y g:i a T')).'</p>';
?>
</body>
</html>
以下是HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>price test</h1>
<p>this $42.56is a price $26.28 test, we will list of tests</p>
<ul>
<li>$5386.235</li>
<li>$42.56</li>
<li>$65.23</li>
<li>$15.25</li>
<li>$28.23</li>
<li>$42.56</li>
<li>$45.23</li></ul>
</body>
</html>
我的问题是, 为什么eregi取出的数组$quote只有两个相同的值,但是html文件中还有很多跟pattern相同的变量,那位高手能解释一下?谢谢 :)
解决方案 »
- 一个异步加载的问题
- php 能不能做到让客户端隔离
- 郁闷,用HTML编写注册表时,怎么对齐啊,有没有人可以帮下我啊。我的作业。。。。
- 为什么session在linux服务器上不能用啊
- php 中文文件名重命名的问题
- 如果做一个社区,模板用smarty好,还是用正则表达式自己写?
- 求救:在把Access数据导入mysql时,出现问题了
- 上面那个正则表达式匹配的问题解决了
- 禁用COPY、UNLINK的情况下,怎样修改服务器的文件?
- 请问现在有没有用php写的搜索引型吗?
- 解释下:function __construct(){}
- 新闻数据表为空时,出现mysql_fetch_object(): supplied argument is not a valid MySQL result resource,该如何解决呢?
$pattern='/\$[0-9]+\.[0-9]+/';//正则错误吧 自己测试一下吧,不知道什么你的$符号和.转义完了还加一个\呢