应为PHP分析错误括号
当我运行以下PHP代码时:应为PHP分析错误括号,php,Php,当我运行以下PHP代码时: <?php $start = "https://en.wikipedia.org"; function follow_links($url) { $doc = new DOMDocument(); $doc->loadHTML(file_get_contents($url)); $linklist = $doc->getElementsByTagName("a"); foreach ($linklist =
<?php
$start = "https://en.wikipedia.org";
function follow_links($url) {
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents($url));
$linklist = $doc->getElementsByTagName("a");
foreach ($linklist = $link) {
echo $link->getAttribute("href")."\n";
}
}
follow_links($start);
将您的foreach
循环更改为此
你需要改变这个
foreach ($linklist = $link) {
对此
foreach ($linklist as $link) {
感谢您,因为您习惯于用其他语言分配变量,所以以前从未真正使用过php。
foreach ($linklist as $link) {