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?

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;
    }

but it shows a blank page.. any idea?

$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;

sorry i dont want to say form it is from :)

// 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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.