Jump to content

[SOLVED] URL Regex Not working.


john_bboy7

Recommended Posts

I its very easy question i guess but i cant figure it out to work it.. here is my code:

 

$r = "<tr><td class="code">http://rapidshare.com/files/173282104/13_20bELOVED.jpg<br>";

preg_match_all("(?<=//rapidshare.com/files/)[a-zA-Z0-9\.\\_:\/^=-]+",$out,$r,PREG_SET_ORDER);

echo $out[0][0] . ", " . $out[0][1] . "<br>";
echo $out[1][0] . ", " . $out[1][1] . "<br>";

 

Well i am trying to extract this link:

 

http://rapidshare.com/files/173282104/13_20bELOVED.jpg

 

Out of the whole html page.. But am i doing something wrong here? i made that pregmatch code from an example given in php help site.. i also tried preg patteren order but still not working.. ???

 

Any help would be appretiated.. :) thanks.

Link to comment
Share on other sites

Anyone? i m waiting for 2 hours.. :P

 

Please try to be more patient... Not trying to sound rude or difficult, but the people in this forum do not evolve around individuals. Responses like yours could actually turn people off, as no one likes others asking out of urgency.

 

As for your code, I noticed that your preg_match_all pattern isn't surrounded by delimiters. You open with (, but don't close with ). [the reason obviously being that you start by using a look behind assertion, but the regex engine treats that first character '(' as a delimiter, thus fails completely as a result. You can read up about preg on our resources page.

 

You can consider something like:

$r = '<tr><td class="code">http://rapidshare.com/files/173282104/13_20bELOVED.jpg<br>...some more code...<a herf="whatever">http://rapidshare.com/files/345721007/22_71hATED.gif</a>';
preg_match_all('#http://rapidshare.com/files/[^ <]+#', $r, $matches);
echo "<pre>".print_r($matches[0], true);

\

 

Notice that I surrounded my full pattern with # on either side. A delimiter can be any non-white space, non alphanumeric ASCII character other than a backslash. So delimiters can be #...#, or !...! or ~...~ You get the idea.. You can use (, <, { or [ as opening delimiters, but then must have the appropriate closing characters as closing delimiters. To make matters worse, you may need to escape some of these characters within your pattern so the regex engine doesn't confuse them as closing delimiters, thus causing problems..so I would recommend staying away from those characters as delimiters.

Link to comment
Share on other sites

First of all i m sorry.. :-[

 

And second.. ur code is indeed correct.. But the problem is .. its not getting links from my webpage i.e. it duz not shows any match...

 

Here is my code:

 

<?php

define("USER_AGENT","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009020911 Ubuntu/8.10 (intrepid) Firefox/3.0.6");
define("USERNAME","?????");
define("PASSWORD","?????");

function loadURL($url,$postData = null)
{
    $ch = curl_init();		   
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);		   
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

    if ($postData)
    {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    }
    curl_setopt($ch, CURLOPT_USERAGENT, USER_AGENT);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE,  "cookie.txt");
    $result = curl_exec ($ch);
    curl_close ($ch);
    return $result;
}


$url = "http://www.??????.com/login.php";

loadURL("http://www.??????.com/login.php","username=".USERNAME."&password=".PASSWORD."&autologin=on&login=Log+in");

$r = loadURL("http://www.??????.com/viewtopic.php?t=1928858",null);

preg_match_all('#http://rapidshare.com/files/[^ <]+#', $r , $matches);
echo "<pre>".print_r($matches[0], true);

?>

 

And its shows empty..

Whats wrong in my code?

 

And thank you for replying.. :)

Link to comment
Share on other sites

Well, for that pattern to work, the pattern has to find that / those values in $r.. So if you echo out $r, what result do you get?

 

If i echo $r then i get the entire page...i mean for e.g take this forum page.. i will get this exact forum page shown with me already logged in...

Link to comment
Share on other sites

If you are getting nothing from the regex, it could well mean there is no code with 'http://rapidshare.com/files/.....' in it. Could you cut and paste a few sample lines involving 'http://rapidshare.com/files/.....' from whatever page you are scanning (not this forum page, but from the site you are interested in)?

 

If no such code can be found, well, nothing I can do about it, as you need to have that tidbit somewhere in the value of $r in order for regex to return those values.

Link to comment
Share on other sites

If you are getting nothing from the regex, it could well mean there is no code with 'http://rapidshare.com/files/.....' in it. Could you cut and paste a few sample lines involving 'http://rapidshare.com/files/.....' from whatever page you are scanning (not this forum page, but from the site you are interested in)?

 

If no such code can be found, well, nothing I can do about it, as you need to have that tidbit somewhere in the value of $r in order for regex to return those values.

 

Should i pm u the the entire code its almost the same but i will put the site name in it so u can check it... And trust me there are more than one rapidshare links in it... but the problem might be here.. they are in code links.. means in coded links where u can not click them..Same like in here.. where u put the codings..

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.