Buying Require regex to parse url from referrer

Discussion in 'Programming' started by Avo19, Jan 26, 2010.

  1. #1
    Need to parse out the url from the referrer and incorparate in my script. The url can be in one of several places within the referrer, so the regex needs to account for that. "Http://" & "www." need to be stripped out.

    Currently I'm parsing keywords from the referrer using following format

    //for_http://searchservice.myspace.com/index.cfm?fuseaction=sitesearch.results&orig=search_Header&type=Web&qry=
     } elseif(preg_match_all("/[\?\&]{1}qry=/i", $str, $regs)) { 
         if(preg_match("/http:\/\/(.*?)\/.*?[\?\&]{1}qry=(.*?)\&.*/i", $str, $regs)) preg_match("/http:\/\/(.*?)\/.*?[\?\&]{1}qry=(.*?)\&.*/i", $str, $regs);
        else 
         if(preg_match("/http:\/\/(.*?)\/.*?[\?\&]{1}qry=(.*?)$/", $str, $regs))  preg_match("/http:\/\/(.*?)\/.*?[\?\&]{1}qry=(.*?)$/i", $str, $regs);
    Code (markup):
    Some examples of referrer formats:

    http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-4588993279191187&output=html&h=600&slotname=0974197517&w=160&lmt=1264515708&flash=10.0.22.87&url=http%3A%2F%2Fwww.farmersalmanac.com%2F&dt=1264515708434&correlator=1264515708434&frm=0&ga_vid=1638420855.1264515145&ga_sid=1264515145&ga_hid=192240200&ga_fc=1&u_tz=-300&u_his=9&u_java=1&u_h=768&u_w=1366&u_ah=728&u_aw=1366&u_cd=32&u_nplug=0&u_nmime=0&biw=1345&bih=635&ref=http%3A%2F%2Fwww.farmersalmanac.com%2Flong-range-weather-forecast%2Fgreat-lakes-midwest-us%2F&fu=0&ifi=1&dtd=16&xpc=AalSlaphtr&p=http%3A//www.farmersalmanac.com
    Code (markup):
    URL to be parsed: farmersalmanac.com

    http://planetgreen.discovery.com/food-health/epa-chemicals-secret.html
    Code (markup):
    URL to be parsed: planetgreen.discovery.com

    http://www.latimes.com/hive/common/includes/google-adsense-content-la.html?client=ca-tribune_news3_html&google_ad_channel=Latimes_story_pos2&page_url=http://www.latimes.com/news/nation-and-world/la-sci-rover27-2010jan27,0,7889844,print.story
    Code (markup):
    URL to be parsed: latimes.com

    http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-4989225397719533&output=html&h=15&slotname=2364369276&w=700&lmt=1264548700&flash=10.0.32.18&url=http%3A%2F%2Fwww.ufostalker.com%2F&dt=1264548700093&correlator=1264548700093&frm=0&ga_vid=1686715506.1264548700&ga_sid=1264548700&ga_hid=1684393810&ga_fc=0&u_tz=-480&u_his=40&u_java=1&u_h=768&u_w=1024&u_ah=704&u_aw=1024&u_cd=32&u_nplug=0&u_nmime=0&biw=1020&bih=505&ref=http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Den%26q%3Dufo%2Bmaps%26btnG%3DSearch%26aq%3Df%26aql%3D%26aqi%3Dg2%26oq%3D&fu=0&ifi=1&dtd=47&xpc=QeYZ92A3BG&p=http%3A//www.ufostalker.com&rl_rc=true&adsense_enabled=true&ad_type=text,image&height=15&width=728&format=fp_al_lp&kw_type=radlink&prev_fmts=728x15_0ads_al_s&rt=ChBLX3tcAAD8SAqDagNnZntSEhRSZWNlbnQgVUZPIFNpZ2h0aW5ncxoIpYlGFvWKd_goAVITCNT7xICbw58CFQx0gwodRSlrcw&hl=en&kw0=Recent+UFO+Sightings&kw1=UFO+Video&kw2=Alien+Pictures&kw3=Real+Alien+Sightings&kw4=UFOs+Area+51+Roswell&okw=Recent+UFO+Sightings
    Code (markup):
    URL to be parsed: ufostalker.com


    Need this done ASAP.
     
    Avo19, Jan 26, 2010 IP
  2. bm4web

    bm4web Well-Known Member

    Messages:
    718
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    hi,

    i have just sent PM, please check it out and let me know.. :cool:
     
    bm4web, Jan 26, 2010 IP
  3. Avo19

    Avo19 Well-Known Member

    Messages:
    220
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    BTW, to clear up any misunderstanding, this is a paid job.
     
    Avo19, Jan 27, 2010 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    Hi,

    It's better to parse_url then grab:
    and preg_replace or preg_match with more simple regular expression.
    If you still need help, please PM me.
    Regards,
    Nick
    Edit: PM with working example sent :)
     
    Last edited: Jan 27, 2010
    koko5, Jan 27, 2010 IP
  5. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Payment OK, iTrader++ left. Thanks Avo19
     
    koko5, Jan 28, 2010 IP