Re: preg_match_all

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 29, 2008 at 01:07:11PM -0500, Chris W wrote:
> What I want to do is find all links in an html file.  I have the pattern  
> below.  It works as long as there is only one link on a line and as long  
> as the whole link is one line.  It seems there should be a way to get  
> this to work with more than one link on a single line.  The work around  
> I have done for now is to read the whole file into a buffer and remove  
> all new lines and then add a new line after every closing a tag.  Then  
> process each line.  There has to be a better way.
>
> Any Ideas?  Also note I don't want to find any a tags that don't have an  
> href.... there probably aren't any but just in case.
>
>
> preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches,  
> PREG_PATTERN_ORDER);

Hi...

I have a little function to explode URLs with the following pattern:

$str = filename;

$pattern = '=^.*<a .* href\="(.*[://]|[:])(\S+)"[^>]*>(.*)</a>.*$=ims';

while (preg_match($pattern, $line, $exploded_url)) {
    some usefull stuff
    returns an array ($exploded_url)
    }

$exploded_url[1] = protocoll;
$exploded_url[2] = URL;
$exploded_url[3] = name of the URL;

greetings
MG

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/CM d- s++: a+ C++++>$ UBL*++++$ P++ L+++ E--- W+++ N+ o-- K- w O- M-
V-- PS++ PE++ Y PGP+++ t--- 5 X++++ R++ tv- b+++ DI D++++  G++ e* h----
r+++ y++++
------END GEEK CODE BLOCK------

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux