phphtmlcurlsimple-html-dombase-tag

How to reset the base tag


So am using simple html dom , i want to retrieve part of the page, that seems to work fine :) but the links are not correct , they are relative to my site... on which i decided to use the base tag instead ....here is what i have

<?php
include('simple_html_dom.php');

$url = "http://bm.erciyes.edu.tr/";
$file = file_get_html($url);

echo "<base href='$url'>";
foreach($file->find('div.onemliduyurular') as $var){
    echo $var->innertext;
}


$url = "http://bm.erciyes.edu.tr/";
?>

<h1>Return to my Site</h1>
<?php

// I want this link here become relative to my site again
echo "<a href='hello.php'>Go This Way</a>"; 

so added this line above the foreach

echo "<base href='$url'>";

is there a way in which i can reset the base tag? or any other alternative ;)

inner text contains this

// get dom node's inner html
    function innertext()
    {
        if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
        if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);

        $ret = '';
        foreach ($this->nodes as $n)
            $ret .= $n->outertext();
        return $ret;
    }

and this is the announcement am pulling


Solution

  • One of the way is done by using absolute url

    ... What if you prepend your url with the relative one that comes from the pulled site....
    As in

    <?php
    foreach($html->find('div.onemliduyurular') as $d) {
        foreach($d->find('a[href]') as $goAway){
            $goAway->href =$url.$goAway->href;
            }
        echo $d->innertext;
    }
    $html->clear();
    unset($html);
    

    I hope it may work with your project