tags:

views:

41

answers:

3

Hi,

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.

A: 

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

spinon
+2  A: 

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.

Artefacto
+2  A: 

.

preg_match_all('/<(p|br\/)>/',$text,$matches,PREG_SET_ORDER);
var_dump($matches);
stillstanding