Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否将文本仅放在循环的第一个结果之后?_Php_Wordpress - Fatal编程技术网

Php 是否将文本仅放在循环的第一个结果之后?

Php 是否将文本仅放在循环的第一个结果之后?,php,wordpress,Php,Wordpress,目前我有这个循环 foreach ($html2->find('.entry-content img') as $image) { $path = $image->src; $start = '<img src="'.$path.'" style="height: auto; width: 100%;margin-bottom: 3px;">'; print htmlspecialchars($start); print '<br&g

目前我有这个循环

foreach ($html2->find('.entry-content img') as $image) {
    $path = $image->src;    
    $start = '<img src="'.$path.'" style="height: auto; width: 100%;margin-bottom: 3px;">';
    print htmlspecialchars($start); print '<br>';
}
foreach($html2->find('.entry content img')作为$image){
$path=$image->src;
$start='';
打印htmlspecialchars($start);打印“
”; }
这是从一个网站上用simple\u html\u dom.php抓取一些图像,这部分工作非常好。但是,我需要使它只在foreach循环中的第一个结果之后返回WordPress
标记

我如何才能做到这一点


谢谢

您可以尝试检查它是否是循环中的第一个,如下所示:

$first = TRUE;

foreach ($html2->find('.entry-content img') as $image) {
$path = $image->src;    
$start = '<img src="'.$path.'" style="height: auto; width: 100%;margin-bottom: 3px;">';

if($first){
    $start .= "<!--more-->";
    $first  = FALSE;
}

print htmlspecialchars($start); print '<br>';
}
$first=TRUE;
foreach($html2->find('.entry content img')作为$image){
$path=$image->src;
$start='';
如果($第一){
$start.=“”;
$first=FALSE;
}
打印htmlspecialchars($start);打印“
”; }
您可以尝试检查它是否是循环中的第一个,如下所示:

$first = TRUE;

foreach ($html2->find('.entry-content img') as $image) {
$path = $image->src;    
$start = '<img src="'.$path.'" style="height: auto; width: 100%;margin-bottom: 3px;">';

if($first){
    $start .= "<!--more-->";
    $first  = FALSE;
}

print htmlspecialchars($start); print '<br>';
}
$first=TRUE;
foreach($html2->find('.entry content img')作为$image){
$path=$image->src;
$start='';
如果($第一){
$start.=“”;
$first=FALSE;
}
打印htmlspecialchars($start);打印“
”; }
一个简单的
if
就可以完成这项工作

$cond = false;
foreach($html2->find('.entry-content img') as $image) {
//Always done
if (!$cond) {
  //Will be called only during the first iterration
  $cond = true;
 }
else if ($cond){
  //This part will always be executed after the first iterration
 }
}

一个简单的
if
就可以完成这项工作

$cond = false;
foreach($html2->find('.entry-content img') as $image) {
//Always done
if (!$cond) {
  //Will be called only during the first iterration
  $cond = true;
 }
else if ($cond){
  //This part will always be executed after the first iterration
 }
}