Search code examples
phpphp4

Get <p> and <br /> tags positions in HTML


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 is any other solution(function) ?

Your help would be appreciated.


Solution

  • 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.