Jump to content

removing url+any thing add to it


tw33ty

Recommended Posts

Hi

i have a php that give an array with a list of url

something like that

Array

(

    [0] => https://secure.delicious.com/register

    [1] => https://secure.delicious.com/login?jump=ub

    [2] => http://delicious.com/

    [3] => http://delicious.com/help/learn

    [12] => http://delicious.com/help/learn

    [13] => http://delicious.com/help/learn

    [14] => http://delicious.com/help/learn

    [15] => http://delicious.com/help/learn

    [16] => http://delicious.com/help/learn

    [17] => #

    [18] => http://delicious.com/

    [19] => http://delicious.com/?view=tags

    [20] => http://delicious.com/recent

    [21] => http://delicious.com/popular/

    [22] => http://www.edutopia.org/podcasting-student-broadcasts

    [23] => http://www.edutopia.org/podcasting-student-broadcasts

    [24] => http://delicious.com/save?url=http%3A%2F%2Fwww.edutopia.org%2Fpodcasting-student-broadcasts&title=Listening%20to%20Themselves%3A%20Podcasting%20Takes%20Lessons%20Beyond%20the%20Classroom%20%7C%20Edutopia&jump=%2F&key=lrHycjxVqTdfQlPTFFSAUVpWqn4-&original_user=

    [25] => http://delicious.com/url/fd670a1ff78b82097ed4ef28c7786369

    [26] => http://delicious.com/popular/podcasting

    [27] => http://delicious.com/popular/podcast

    [28] => http://delicious.com/popular/podcasts

    [29] => http://delicious.com/popular/web2.0

    [30] => http://delicious.com/popular/technology

    [31] => http://chatpad.jp/

    [32] => http://chatpad.jp/

    [83] => http://delicious.com/popular/activerecord

    [84] => http://delicious.com/popular/rubyonrails

    [85] => http://meecss.com/

    [86] => http://meecss.com/

    [87] => http://delicious.com/save?url=http%3A%2F%2Fmeecss.com%2F&title=MeeCSS%20-%20CSS%20Galleries%20submission%20helper&jump=%2F&key=lrHycjxVqTdfQlPTFFSAUVpWqn4-&original_user=

    [88] => http://delicious.com/url/06c51bb2b037bbf1682fe56ca9cf3fd6

    [89] => http://delicious.com/popular/css

    [90] => http://delicious.com/popular/gallery

    [91] => http://delicious.com/popular/webdesign

    [92] => http://delicious.com/popular/tools

    [93] => http://delicious.com/popular/inspiration

    [94] => http://mashable.com/2009/07/24/education-social-media/

 

)

 

i wanna to remove any *.delicious.*/*/* address from this array

 

here is the code

<?php
  $link_to_dig = "http://delicious.com/";

  $original_file = @file_get_contents($link_to_dig);
  if(!$original_file)
    die("Error loading {$link_to_dig}");

  $path_info = parse_url($link_to_dig);
  $base = $path_info['scheme'] . "://" . $path_info['host'];

  $stripped_file = strip_tags($original_file, "<a>");
  $fixed_file = preg_replace("/<a([^>]*)href=\"\//is", "<a$1href=\"{$base}/", $stripped_file);
  $fixed_file = preg_replace("/<a([^>]*)href=\"\?/is", "<a$1href=\"{$link_to_dig}/?", $fixed_file);
  preg_match_all("/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^<]*)<\/a>/is", $fixed_file, $matches);

  //DEBUGGING

  //$matches[0] now contains the complete A tags; ex: <a href="link">text</a>
  //$matches[1] now contains only the HREFs in the A tags; ex: link

  $result = print_r($matches[1], true);
  print "<pre>" . $result . "</pre>";

Link to comment
Share on other sites

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.