【发布时间】:2010-08-02 21:41:40
【问题描述】:
Function 中的代码正在运行,但由于我想处理多个 Url,因此我想将其设为一个函数,使用数组来获取要处理的 url。这是代码:
<?php
$site = array("http://www.ihr-apotheker.de/cs1.html", "http://www.ihr-apotheker.de/cs2.html", "http://www.ihr-apotheker.de/cs3.html");
function parseNAI($sites)
{
foreach ($sites as $html)
{
$clean_one = strstr($html, '<p>');
$clean_one_class = str_replace('<p><span class="headline">', '<p class="headline gruen"><span>', $clean_one);
$clean_one_class_a = strip_tags($clean_one_class, '<p><span><a>');
$clean_one_class_b = preg_replace("/\s+/", " ", $clean_one_class_a);
$str_one = preg_replace('#(<a.*>).*?(</a>)#', '$1$2', $clean_one_class_b);
$ausgabe_one = strip_tags($str_one, '<p>');
echo $ausgabe_one;
}
};
parseNAI($site);
?>
我的问题在哪里,因为函数在 foreach 开始时停止工作...... 提前感谢您的帮助!
【问题讨论】:
-
函数的右花括号后不需要分号。看起来您的 foreach 循环需要在执行其他操作之前从
$html中的 URL 实际加载页面内容。