Jump to content

Recommended Posts

I need to get urls from this page..

http://crappytools.com/pingurls/list.asp

i am using my own function to get urls. tell me how is it.. If you have any idea/suggestion then plz let me know.

<?php
function line_stripper($url,$checker,$filter)
{
$file = file_get_contents($url);
$string = explode("\n",$file);
$j=0;
for($i=1;$i<=count($string); $i++)
{
$res=1;
$res = strpos($string[$i],$checker);
if($res === 0)
{
    $short = strpos($string[$i],$filter);
    if($short == "" )
    {
        $list[$j] = $string[$i];
        $j++;
    }
}
}
return $list;
}
$result = line_stripper("http://crappytools.com/pingurls/list.asp","http","fails");
print_r($result);
?>

$checker= "http" As we need urls alone then

$filter=We dont need failed urls. So we filter from result urls.

Link to comment
https://forums.phpfreaks.com/topic/56689-need-comments-about-my-function/
Share on other sites

Not too bad. You could just shorten it fully using regex. But for now you could just tidy the function up abit with using a foreach loop:

<?php

function line_stripper($url, $checker, $filter)
{
    $file = file_get_contents($url);

    $lines = explode("\n", $file);

    $list = array();

    foreach($lines as $line)
    {
        if( strpos($line, $checker) === 0 )
        {
            $short = strpos($line, $filter);

            if( empty($short) )
            {
                $list[] = trim(strip_tags($line));
            }
        }
    }

    return $list;
}

$result = line_stripper('http://crappytools.com/pingurls/list.asp', 'http', 'fails');

echo '<pre>' . print_r($result, true) . '</pre>';

?>

 

I used trim and strip_tags function as you code was returning the <br> tag. ANd trim to just remove any whitespace characters at the beginning/end of the url.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.