str_ireplace with replace ends my html tag.
$txt = '<p><strong>Add on </strong>[number],<strong> number nr </strong></p>';
$htmlValue = '<div class="resizing-input"><input type="text" value="1"><span style="display:none"></span></div>';
$text = str_ireplace('[number]', $htmlValue, $txt);//It needs to be case-insensitive so str_ireplace not str_replace.
echo'<pre>';print_r($text);echo'</pre>';die;
//return: <pre><p><strong>Add on </strong></p><div class="resizing-input"><input type="text" value="1"><span style="display:none"></span></div>,<strong> number nr </strong><p></p></pre>
//should return: <pre><p><strong>Add on </strong><div class="resizing-input"><input type="text" value="1"><span style="display:none"></span></div>,<strong> number nr </strong></p></pre>
Why it does like that?
I want to replace string between [] to html but it ends another html </p>
tag. Same thing happens with str_replace too.
The thing is I can't write <div>
tag inside a <p>
element.
Syntax of the p element does not allow a div child, and the end tag </p>
may be omitted, the validator (and a browser) implies </p>
when it encounters a <div>
tag when parsing ap element. That is, when p is being parsed (or “is open”), the start tag of a div element implicitly closes it.
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.