The Javascript stripper used preg_replace() to find and replace Javascript. To turn it into a link extracter you use preg_match_all() find all the links and store them in an array:
preg_match_all( "@<a[^>]*>[^>]*(/a>)@i", $file, $links_list);
| Analysis | |
|---|---|
| @ | The character I chose for a delimiter |
| <a | Pattern starts with "<a" |
| [^>]* | Followed by any length string of characters not a ">" |
| > | Followed by a ">" |
| [^>]* | Followed by any length string of characters not a ">" |
| (/a>) | Ending in "/a>" |
| i | Case insensitive |
| $file | The string being tested |
| $links_list | The array that holds the results |
Now that we have all of the links in an array, we can use foreach() to loop through the array and output the links:
foreach( $links_list[0] as =>)
{ echo "$var<br />\n"; }
Note that like the Javascript stripper, it adds a base href to the results to fix broken relative links so you need to use an absolute URL for the form action.
|
|
|