I have to get <p> and <br />
tags positions in whole html code. If I use strpos function, I get only first tag position. Does it possible to make this function greedy or something ? Or maybe there开发者_如何学JAVA is any other solution(function) ?
Your help would be appreciated.
strpos
has a third optional argument that allows you to specify an offset from where you want to start searching. Fill it with the position of the last occurrence + 1.
However, this all looks a bit fishy. If you trying to read or write arbitrary HTML, you ought to use DOMDocument
or another extension/library designed for HTML parsing.
.
preg_match_all('/<(p|br\/)>/',$text,$matches,PREG_SET_ORDER);
var_dump($matches);
You should look into preg_match instead of strpos as then you can use a regular expression and supply the global flag so that it searches the whole HTML for every match.
http://php.net/manual/en/function.preg-match.php
精彩评论