How to get tag content?
<p>Im making a script to get other pages content, and right now im working on a function that should get tag content... but im a bit stuck :D</p>

<pre><code>found a new tag of same kind inside tag...
nothing found...
1111
2222
</code></pre>

<p>is printed.</p>

<pre><code>&lt;?php

function d($toprint)
{
    echo $toprint."&lt;br /&gt;";
}

function GetTagContents($source, $tag, $pos)
{   
    $startTagPos        = strpos( $source, "&lt;".$tag, $pos );
    $startTagEndPos     = strpos( $source, "&gt;", $startTagPos )+1;

    $endTagPos          = strpos( $source, "&lt;/".$tag, $startTagEndPos);

    $lastpos = $startTagPos+1;    
    while( $lastpos != False )
    {
        $newStartTagPos = strpos( $source, "&lt;".$tag, $lastpos );

        if( $newStartTagPos == False )
        {
            d("nothing found...");
            $lastpos = False;        
        }
        else if( $newStartTagPos &gt; $endTagPos )
        {
            d("out of bounds...");
            $lastpos = False;
        }
        else
        {
            d("found a new tag of same kind inside tag...");
            $lastpos =  $newStartTagPos+1;       
            $endTagPos  = strpos( $source, "&lt;/".$tag, $newStartTagPos);
        }
    }

    return substr($source, $startTagEndPos, $endTagPos-$startTagEndPos);
}
?&gt;
&lt;html&gt;

    &lt;body&gt;
    &lt;?php

    d(GetTagContents('&lt;div&gt;1111&lt;div&gt;2222&lt;/div&gt;3333&lt;/div&gt;', "div", 0));

    ?&gt;
    &lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>someone got any ideas?</p>
