tags:

views:

103

answers:

5

Hi ,

i want to pick all directory url from this site,Click Here

i did the pregmatch, but it retrieve entire site URL,means unnecessary url links also

rendering ,

Here is my code My code

So finally what i want is , i want all submission link from that site....

A: 

You'll want a HTML parser for that. HTML is irregular, so regular expressions don't work well.

Ignacio Vazquez-Abrams
here dom not enabled. looking reply in preg match..Boss
Bharanikumar
A: 

I have a nifty little tool for you to make regex keys with.

go check out RegExr at gskinner.com

additionally I believe this is the pattern your looking for. for an anchor to be matched it must have a full url including the domain. I will output the url, domain, and path in an array. see below.

preg_match('/http:\/\/(?P[a-z0-9/]+\.[\w]+)(?P[\/\?\w\.=\&]+)?)[\s\w="]+>/', $site, $anchors);

$url = $anchors['url'];
$domain = $anchors['domain'];
$path = $anchors['path'];

let me know how it goes. I did not test this so I apologize if there is an error.

Robert Hurst
A: 

To use a regular expression for this you need some consistent delimiters. Thankfully, the URLs you want - and only those you want - seem look like this in source:

target="_blank">-->the url is here<!--</a>-->

Meaning the regular expression you'd want is:

@target="_blank">-->(?P<url>.+?)<!--</a>-->@

Where matches from the first capture group, indexed under "url", will contain the - surprise - URLs. Why the named capture group? Just seems easier to figure out what it is you're doing when you look back at your code.

erisco
A: 

I tried running this and it seems to work, only changed the regex

<?php
for($i=0;$i<=25;$i++){
    $site_url = "http://www.directorymaximizer.com/index.php?pageNum_directory_list=$i";
    $preg_math =  file_get_contents($site_url);
    $regex = '@-->(https?://[^<]*)<\!--@'; 
    preg_match_all($regex, $preg_math, $matches, PREG_PATTERN_ORDER); 

    foreach($matches as $key=>$val){
    if($val!="" && !is_numeric($val)){
        foreach(array_unique($val) as $key1=>$val1){
            if( $val1!="" && !is_numeric($val1)){

             echo $val1;
             echo "<br />\n";

            }
        }   
    }
}
}
Kristoffer S Hansen
You don’t need to escape the `!` in your regular expression.
Gumbo
Yeah, you're right, luckily regexes ignore that kind of sillyness
Kristoffer S Hansen
A: 

thanks problem fixed

Bharanikumar