0

I am using PHP Simple HTML DOM Parser to fetch urls, but i got an error while fetching links. Have a look at this script:

$result = str_get_html($result);
foreach($result->find('a') as $element)
$result = str_get_html($result);
$result = str_replace('http://', '', $result);
foreach($result->find('a') as $elementa)
echo $element->href;
echo $elementa->href;

Here I want to fetch all links for twice, first time urls in $element->href will fetch links starting with http:// and in $elementa->href will fetch links without http://

But this shows only a blank page. Any idea?

3
Contributors
9
Replies
14
Views
5 Years
Discussion Span
Last Post by sagar.shetty.946
0

Put your foreach loops in {}

    $result = str_get_html($result);
    foreach($result->find('a') as $element){
    $result = str_get_html($result);
    $result = str_replace('http://', '', $result);
    }
    foreach($result->find('a') as $elementa){
    echo $element->href;
    echo $elementa->href;
    }
0
$result = file_get_html('http://www.example.com/');

foreach($result->find('a') as $element){
    $result = str_replace('http://', '', $result);
}

foreach($result->find('a') as $elementa){
    echo $element->href;
    echo $elementa->href;
}

As i edited in (may have been as you were replying), str_get_html is used for loading in strings.

Try the above.

Also this is not a form

it is form

$html = file_get_html('http://www.example.com');
$result = $html;

Edited by Squidge

0
// get simple_html_dom from http://simplehtmldom.sourceforge.net/
include_once('simple_html_dom.php'); 

// Add url in place of "URL"
$result = file_get_html(URL);

// Searchs for 'a' tags
$result_a = $result->find('a');

// Replace 'http://'
foreach($result_a as $resultA){
    echo str_replace('http://','',$resultA);
}

// Show untouched
foreach($result_a as $resultA){
    echo $resultA . "<br/>";
}

Should do it for you

0

hey the reason for this error is coz the simple html dom dosent return the object if the size of the response from url is greater then 600000...so u can void it by changing the simple_html_dom.php file....inside file_get_html function the the if condition...remove strlen($contents) > MAX_FILE_SIZE....
this will solve ur issue

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.