搜索时php strpos不工作<;br/>&书信电报;br/>;在nl2br()之后
我无法正确使用strpos。如果我搜索搜索时php strpos不工作<;br/>&书信电报;br/>;在nl2br()之后,php,strpos,Php,Strpos,我无法正确使用strpos。如果我搜索,它会找到它。如果我搜索,无论中间是否有空格,它都不会,使用htmlspecialchars我可以判断字符串中是否有空格 <?php $picArray = glob('projectData/' . $data['folder'] . '/*.jpg',GLOB_BRACE); $text = nl2br($data['definition']).'<br />'; $cutP = 0; forea
,它会找到它。如果我搜索
,无论中间是否有空格,它都不会,使用htmlspecialchars
我可以判断字符串中是否有空格
<?php
$picArray = glob('projectData/' . $data['folder'] . '/*.jpg',GLOB_BRACE);
$text = nl2br($data['definition']).'<br />';
$cutP = 0;
foreach($picArray AS $insert) {
if(strpos($text,'<br /> <br /> <br />',$cutP) !== FALSE){
$cutP = strpos($text,'<br /> <br /> <br />',$cutP)+6;
echo $cutP.'_';
$str_to_insert = '<img class="inTextImg" title="int" src="'.$insert.'" />';
$text = substr($text, 0, $cutP) . $str_to_insert . substr($text, $cutP);
}
else {
echo 'haha';
$text .= '<img class="inTextImg" title="outText!" src="'.$insert.'" />';
}
}
?>
感谢您的想法。您尝试过使用preg_match()吗
if(预匹配(“\(
)+\”,$text)>0){
//代码
}
在正则表达式上不是100%,但您需要一个检查一个或多个br标记的标记这是因为
nl2br
将原始换行字符保留在'
'
之后。您需要在要搜索的字符串中包含换行符。因为可以有几种不同的模式,所以最容易使用regexp来匹配它:
$text = preg_replace('/(?:<br \/>\r?\n?){3}/', $str_to_insert, $text);
$text=preg\u replace(“/(?:
\r?\n?{3}/”,$str\u to\u insert,$text);
echo$text的输出是什么代码>?也许你认为是你能把这个问题分解成一个简单的脚本吗?没有任何关于fodler结构等的参考。只需给出一个失败的例子。一般来说,最好在这类任务中使用正则表达式。Bondye:echo$text准确地回显文本,浏览器正确地解释了
。ficuscr:不幸的是,不,Lukasz不能很好地转到核心strpos将找到
,但不会找到
,即使它100%确定它是在$text中。我将尝试常规,但我需要找到的字符串+1的位置来解释为什么strpos
无法与字符串匹配。谢谢,我需要将
保持在适当的位置,所以我做了$text=str\u替换(“\n”,“”,$text)$text=str_replace(“\r”,”$text);
$text = preg_replace('/(?:<br \/>\r?\n?){3}/', $str_to_insert, $text);