I have a line of code here and $post['post']
is a string that may contain html tags:
echo mb_strpos(mb_substr($post['post'], 299), " ");
I want to find the first occurrence of a whitespace character from the 299th offset of $post['post']
, but I want to ignore html tags. For example, I want to ignore the whitespace in the following string:
<br />
How do I ignore the whitespace inside such html tags?
You should use strip_tags
(More info here: http://php.net/manual/en/function.strip-tags.php):
echo mb_strpos(mb_substr(strip_tags($post['post']), 299), " ");
If you want to allow some HTML tags, you can do it as here:
echo mb_strpos(mb_substr(strip_tags($post['post'], "<a><b><span>"), 299), " ");
From the documentation, you can use the function strip_tags:
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "
";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
So in your case:
echo mb_strpos(mb_substr((strip_tags($post['post']), 299)," ");