protected function replace(Crawler $crawler, $element, $callback)
    {
        $function = function (Crawler $crawler) use ($callback)
        {
            $node = $crawler->getNode(0);

            $html = $node->ownerDocument->saveHtml($node);

            $text = $callback($crawler, (string) $html);

            return array((string) $html, (string) $text);
        };

        $items = $crawler->filter($element)->each($function);

        $html = (string) $crawler->html();

        foreach ((array) $items as $item)
        {
            $html = str_replace($item[0], $item[1], $html);
        }

        return new Crawler((string) $html);
    }
protected function replace(Crawler $crawler, $element, $callback)
    {
        $function = function (Crawler $crawler) use ($callback)
        {
            $node = $crawler->getNode(0);

            $html = $node->ownerDocument->saveHtml($node);

            $text = $callback($crawler, (string) $html);

            return array((string) $html, (string) $text);
        };

        $items = $crawler->filter($element)->each($function);

        $html = (string) $crawler->html();

        foreach ((array) $items as $item)
        {
            $html = str_replace($item[0], $item[1], $html);
        }

        return new Crawler((string) $html);
    }
protected function replace ( Crawler $ crawler , $ element , $ callback ) { $ function = function ( Crawler $ crawler ) use ( $ callback ) { $ node = $ crawler -> getNode ( 0 ) ; $ html = $ node -> ownerDocument -> saveHtml ( $ node ) ; $ text = $ callback ( $ crawler , ( string ) $ html ) ; return array ( ( string ) $ html , ( string ) $ text ) ; } ; $ items = $ crawler -> filter ( $ element ) -> each ( $ function ) ; $ html = ( string ) $ crawler -> html ( ) ; foreach ( ( array ) $ items as $ item ) { $ html = str_replace ( $ item [ 0 ] , $ item [ 1 ] , $ html ) ; } return new Crawler ( ( string ) $ html ) ; }
Replaces a specified HTML tag based from the given callback.

@param  \Pilipinews\Common\Crawler $crawler
@param  string                     $element
@param  callable                   $callback
@return \Pilipinews\Common\Crawler
Replaces a specified HTML tag based from the given callback .