Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post

    Extracting the end of a URL

    Hey there, I am trying too make a script that can check URL's, which I managed too do with no problem at all. I was wondering was there a way my users can enter multiple urls into a textbox and have the script extract the end of each URL.

    For example, the user submits:

    http://mydomain.com/files/13039621/2...art28.rar.html

    I want the script too delete the first part so it is left with:

    /13039621/2k5pro.part28.rar.html

    and place it in an array. It would also need to be able to take a bunch of links at one time, such as:

    http://mydomain.com/files/35539621/2...art28.rar.html
    http://mydomain.com/files/13242343/2...art29.rar.html
    http://mydomain.com/files/13423621/2...art30.rar.html
    http://mydomain.com/files/13044421/2...art31.rar.html
    http://mydomain.com/files/13252331/2...art32.rar.html
    http://mydomain.com/files/12449621/2...art33.rar.html

    Thanks for your time and effor in helping me.

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here you go:
    http://us3.php.net/parse_url

    Code:
    $url_parts = parse_url($url);
    echo $url_parts['path'];

  • #3
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah, I had only answered part of your question.. here's the rest of your answer...
    PHP Code:
    <?php
    $urls 
    = <<<URLS
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    URLS;

    $urls split("\n"$urls);

    $paths = array();
    foreach (
    $urls as $url) {
        
    $path parse_url($url);
        
    $paths[] = $path['path'];
    }

    print_r($paths);
    ?>

  • #4
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Hey, thanks for the quick reply,

    I suppose I should have mentioned that im sort of new too PHP lol, so go easy on me

    I tried the code you wrote in your last post and here's wha tit outputted:

    Array ( [0] => /files/35539621/2k5pro.part28.rar.html_ [1] => /files/35539621/2k5pro.part28.rar.html_ [2] => /files/35539621/2k5pro.part28.rar.html_ [3] => /files/35539621/2k5pro.part28.rar.html_ [4] => /files/35539621/2k5pro.part28.rar.html_ [5] => /files/35539621/2k5pro.part28.rar.html )

    I see that you got it too strip it down and you learned me a new function, with this I tried too make my own code to have a go because your code confused me:

    PHP Code:
    <?

    $url 
    "
    http://www.whereisit.org/whereis/1.rar.html
    http://www.whereisit.org/whereis/2.rar.html
    http://www.whereisit.org/whereis/3.rar.html
    http://www.whereisit.org/whereis/4.rar.html
    http://www.whereisit.org/whereis/5.rar.html
    http://www.whereisit.org/whereis/6.rar.html
    "
    ;

    $urls split("\n"$urls);

    $num count($urls);
    $i 0;
    while (
    $i $num) {
    $url parse_url($url);
    $url $url['path'];
    echo 
    "$url";
    $i++;
    }
    ?>
    but this outputted:

    /whereis/1.rar.html__http://www.whereisit.org/whereis/2.rar.html__http://www.whereisit.org/whereis/3.rar.html__http://www.whereisit.org/whereis/4.rar.html__http://www.whereisit.org/whereis/5.rar.html__http://www.whereisit.org/whereis/6.rar.html__

    lol, which is not what I was going for; so back to your code. is that what you wanted it too output?

    Is there anyway of just getting it too output

    /files/35539621/2k5pro.part28.rar.html
    /files/35539621/2k5pro.part28.rar.html
    /files/35539621/2k5pro.part28.rar.html
    /files/35539621/2k5pro.part28.rar.html
    /files/35539621/2k5pro.part28.rar.html

    ?

    Thanks for your reply and your time

  • #5
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $urls 
    = <<<URLS
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    http://mydomain.com/files/35539621/2k5pro.part28.rar.html
    URLS;

    $urls split("\r\n"$urls);

    $paths = array();
    foreach (
    $urls as $url) {
        
    $path parse_url($url);
        
    $path['path'].'<br />';
    }

    ?>
    like that?

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    hmm, I may have got it wrong. I user your original code and printed the results like this:

    echo"$paths[1] $paths[2]";

    But now it prints them with a "_" at the end.

    /files/35539621/2k5pro.part28.rar.html_
    /files/35539621/2k5pro.part28.rar.html_

    How ca I get rid of the _ at the end ?

    Thanks again.

  • #7
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How ca I get rid of the _ at the end ?
    PHP Code:
    echo rtrim("$paths[0]""_"); 

  • #8
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Thanks both for your contributes, I think I can manage from here, but I will reply if I need any mre help. Once again, thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •