I’m having trouble using strpos correctly. if I search for<br /> it will find it. If I search for <br /><br /><br /> with or without space between, it won’t and using htmlspecialchars I can tell the string is full of it.
<?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.'" />';
}
}
?>
Thank your for your ideas.
This is because
nl2brkeeps the original line break characters in place, just after the'<br />'. You need to include the line break characters in the string to search for. Since there can be a few different patterns for this it’s easiest to use a regexp to match it: