strpos无法返回一个字符串在另一个字符串中的位置


The strpos is fails to return the postion of a string in another string

strpos失败,在循环中打印描述。原因是什么呢?对于某些字符串,它是有效的。但是在这里它不起作用。

$text ="<ul><li>*Compared with the EXR Processor Pro.</li><li>**Equipped with XF27mmF2.8 in High Performance mode.</li><li>***MF mode.</li></ul>";
$description = "The adoption of the dual CPU and improved performance has doubled the processing speed when compared with the previous generation processor*, the start-up time has also improved to only approx. 0.5 sec.** Working in tandem with the high-speed signal readout of the X-Trans CMOS II sensor, the processor reduces the shooting interval to 0.5 sec.*** and shutter time lag to 0.05 sec<br /><ul><li>*Compared with the EXR Processor Pro.</li><li>**Equipped with XF27mmF2.8 in High Performance mode.</li><li>***MF mode.</li>
</ul>";

if($text!="" && strpos($description,$text) === false)
                    {
                        echo $description;exit;
                    }

您需要删除额外的空格,与$description中的$text字符串相同尝试

$text ="<ul><li>*Compared with the EXR Processor Pro.</li><li>**Equipped withXF27mmF2.8 in High Performance mode.</li><li>***MF mode.</li></ul>";
$description = "The adoption of the dual CPU and improved performance has doubled the processing speed when compared with the previous generation processor*, the start-up time has also improved to only approx. 0.5 sec.** Working in tandem with the high-speed signal readout of the X-Trans CMOS II sensor, the processor reduces the shooting interval to 0.5 sec.*** and shutter time lag to 0.05 sec<br /><ul><li>*Compared with the EXR Processor Pro.</li><li>**Equipped withXF27mmF2.8 in High Performance mode.</li><li>***MF mode.</li></ul>";
if($text!="" && strpos($description,$text) === false) {
    echo $description;exit;
}

那是因为新行在最后一行之前所以这不是相同的

尝试删除新行

$text ="<ul><li>*Compared with the EXR Processor Pro.</li><li>**Equipped with XF27mmF2.8 in High Performance mode.</li><li>***MF mode.</li></ul>";
$description = "The adoption of the dual CPU and improved performance has doubled the processing speed when compared with the previous generation processor*, the start-up time has also improved to only approx. 0.5 sec.** Working in tandem with the high-speed signal readout of the X-Trans CMOS II sensor, the processor reduces the shooting interval to 0.5 sec.*** and shutter time lag to 0.05 sec<br /><ul><li>*Compared with the EXR Processor Pro.</li><li>**Equipped with XF27mmF2.8 in High Performance mode.</li><li>***MF mode.</li>
</ul>";
// remove the new lines
$text = preg_replace('/'n/', '', $text) ;
$description = preg_replace('/'n/', '', $description) ;
if($text!="" && strpos($description,$text) === false)
{
    echo $description;exit;
}
相关文章: