Re: preg_match_all

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

 



On Thu, 2008-05-29 at 14:20 -0400, Robert Cummings wrote:
> On Thu, 2008-05-29 at 13:07 -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);
> 
> Your preg isn't going to return the URLs (even if it works), it's going
> to return the labels of the links. But anyways...

Actually it returned both, just not how I had thought first. I forgot to
delete the above after I realized. My solution below works
nonetheless :)

> <?php
> 
> $content = implode( '', @file( 'http://www.php.net' ) );
> 
> if( preg_match_all(
>         '#(<a[^>]+href[^>]+>)(.*)</a>#Umis', $content, $bits ) )
> {
>     print_r( $bits );
> }
> 
> ?>
> 
> Cheers,
> Rob.


-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
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