I have this problem
This it works:
foreach($inzeraty->find("a") as $nazov)
{
echo $nazov."<br />";
}
but I need just first tag "a"
and this NOT work:
foreach($inzeraty->find("a", 0) as $nazov)
{
echo $nazov."<br />";
}
Error: Invalid argument supplied for foreach()
You may try:
$first_anchor = $inzeraty->find("a", 0);
echo $first_anchor;
From the docs: // Find (N)th anchor, returns element object or null if not found (zero based) It returns one only element, not an array, so you cannot loop over it.
将其视为数组, echo $inzeraty->find("a")[0];
i will suggest to count and display the first. as the following:
$i = 0;
foreach($inzeraty->find("a") as $nazov)
{
$i++;
if($i == 1)
echo $nazov."<br />";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.