Jump to content

abhi_madhani

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Everything posted by abhi_madhani

  1. Hi People, Please let me know is my introduction of problem not well presented or am I trying to do something that is not possible. Regards, Abhishek
  2. Hi, Any help would be appreciated in making Recursive function for this code. Regards, Abhishek
  3. Hi Phpfreaks, I have written this following code, it take any given URL of, and searches and list all 'ABC' links found in that given page. Then it goes through each 'ABC' link or page, searches and list all 'XYZ' links. The code works perfectly till here. Now I am planning to recursive search, where if more 'ABC' links are present inside each 'ABC' page, it should search and list them and 'XYZ' links, and this could go to many levels deep. It is more or less similar to 'Recursive Directory Listing' which lists the directory structure of folder and files, but in HTML page. I am still learning PHP Basic's, so any help even in simplifying my method of code would be grateful. I have attached the dummy file that I have been working on, kindly find it attached. Example :: ABC page ABC Link 1 XYZ Link 1.1 XYZ Link 1.2 XYZ Link 1.3 ABC Link 2 XYZ Link 2.1 XYZ Link 2.2 ABC Link 3 ABC Link 3-1 XYZ Link 3-1.1 XYZ Link 3-1.2 XYZ Link 3-1.3 ABC Link 3-2 XYZ Link 3-2.1 XYZ Link 3-2.1 XYZ Link 3-2.1 XYZ Link 3.1 XYZ Link 3.2 ABC Link 4 My code is as follows ...... <?php $url = "abclistA.html"; $needle = "abc"; $needle1 = "xyz"; echo '<table border="1">'; ABCfound: $acontents = file_get_contents($url); if (strpos($acontents, $needle)==!false) { preg_match_all('/id\s*=\s*\"abcs\".*?<\/table>a/isU',$acontents,$amatches); preg_match_all('/<a\s*href\s*=\s*\"(.*)\"\s*>\s*(.*)<\/a>/iSU',$amatches[0][0],$abc); foreach ($abc[0] as $akey => $abcrecord) { echo '<tr><td>'.$abc[2][$akey].'</td></tr>'; $xcontents = file_get_contents($abc[1][$akey]); if(strpos($xcontents, $needle1)!==false) { preg_match_all('/id\s*=\s*\"xyz\".*?<\/table>x/isU',$xcontents,$xmatches); preg_match_all('/<a\s*href\s*=\s*\"(.*)\"\s*>\s*(.*)<\/a>/iSU',$xmatches[0][0],$xyz); foreach ($xyz[0] as $xkey => $xyzrecord) { echo '<tr><td>'.$xyz[2][$xkey].'</td></tr>'; } // Planning to use this 'goto' shortcut, that when it again find ABC link inside ABC page, // it should go to begining of this code and rerun it. // However this time $url will be changed with suburl that needs to scanned. // This doesn't seem to work. /*if (strpos($xcontents, $needle)==!false) { $url = $abc[1][$akey]; echo " S-MF "; goto ABCfound; } else { echo " S-MNF "; } */ } else { echo " SNF "; } } } else { echo " MNF "; } echo '</table>'; ?> 18464_.zip
  4. I am trying to extract URL's from html page by using following Regular Expression. <a href=" (....till....) "> Name </a> preg_match_all('/<\s*a\s+[^>]*href\s*=\s*[\"\']?([^\"\'>]+)[\"\']>(.*)<\/a>/isU' It works perfectly on most URL's. But it fails to recognise following kind of urls in HTML. http://en.wikipedia.org/wiki/B'ham - Note the single quotation in the B'ham. The URL's in the HTML are not encoded for special characters, hence I have to build my regex to count in URL's which have special characters in them. Could anyone guide me for solutions towards this bend?
×
×
  • 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.