Help me with PHP: Simple HTML DOM Parser, I would integrate to my wordpress blog to find link with same title on another website

Im sorry the code is ugly just newbie here, I have this code

require('simple_html_dom.php');

$title = get_the_title($post->ID);
//$title = "12 Years";

function isAscii($str) {
    return mb_check_encoding($str, 'ASCII');
}
if (isAscii($title)){
    setlocale(LC_ALL, 'en_US.UTF8');
    $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
}
else {
    $clean = $title;
}

//remove all unwanted characters
$res = preg_replace("/[^a-zA-Z0-9 ]/", "", $clean);
$untrimmed = preg_replace('/s+/', ' ', $res);
$trimmed = trim($untrimmed);


$getgo = file_get_html('http://example.com/search/'. urlencode($trimmed));
// Find link
foreach($getgo->find('a[title]') as $element){
    $judulgo = $element->title;
    if ($judulgo == $title){
        $okgo = $element->href .'index.html';
    }
}

$geton = file_get_html('http://example.net/search/'. urlencode($trimmed));
foreach($geton->find('a[title]') as $element){
    $judulon = $element->title;
    if ($judulon == $title){
        $okon = str_replace("category/","blog/",$element->href);
    }
}

$getgo->clear();
$geton->clear();
unset($getgo);
unset($geton);

at my test, when I define the $title = “12 Years”; it works

however when I use the function to call the $title = get_the_title($post->ID); of my wordpress blog I get an error

PHP message: PHP Fatal error:  Call to a member function find() on a non-object in /cari.php on line 24
[error] FastCGI sent in stderr: "PHP message: PHP Warning:  file_get_contents(http://example.com/search/12+Years): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /simple_html_dom.php on line 76

Something wrong are on this, maybe another let me know

foreach($getgo->find('a[title]') as $element){

Read more here: Call to a member function find() on a non-object, wordpress same title


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: