This question is a continuation of my previous question:
I have a text like this :
<ORGANIZATION>Head of Pekalongan Regency</ORGANIZATION>, Dra. Hj.. Siti Qomariyah , MA and her staff were greeted by <ORGANIZATION>Rector of IPB</ORGANIZATION> Prof. Dr. Ir. H. Herry Suhardiyanto , M.Sc. and <ORGANIZATION>officials of IPB</ORGANIZATION> in the guest room.
With the answer code from my question before and PREG_OFFSET_CAPTURE
added like this :
function get_text_between_tags($string, $tagname) {
$pattern = "/<$tagname\b[^>]*>(.*?)<\/$tagname>/is";
preg_match_all($pattern, $string, $matches, PREG_OFFSET_CAPTURE);
if(!empty($matches[1]))
return $matches[1];
return array();
}
I get an output:
Array (
[0] => Array ( [0] => Head of Pekalongan Regency [1] => 14 )
[1] => Array ( [0] => Rector of IPB [1] => 131 )
[2] => Array ( [0] => officials of IPB [1] => 222 ) )
14, 131, 222 are the index of character when matching pattern. Can I get the index of word? I mean the output like this :
Array (
[0] => Array ( [0] => Head of Pekalongan Regency [1] => 0 )
[1] => Array ( [0] => Rector of IPB [1] => 15)
[2] => Array ( [0] => officials of IPB [1] => 27 ) )
Is there any other way than PREG_OFFSET_CAPTURE
or need more code? I have no idea.
Thanks for help. :)