Reply to Re: Find urls in plain text files

Your name:

Reply:


Posted by Carl on 11/02/07 21:15

"Sanders Kaufman" <bucky@kaufman.net> writes:
> Does it make your eyes and ears bleed,the way it does mine?
> Been doin this stuff since the 70's - but regex still makes me cry.
>
> On that note, I am at the moment, writing a function that could sure benefit
> from some regex.
> I just want to see if a string starts with "http(s)://", "news:", "mailto:",
> "ftp:".
> That's a pretty simple regex, right?
> Hoooowwww?

This should get you started:

$pattern = '/^(http(s)?:\/\/|news:|mailto:|ftp:)/';

$tests = array('http://www.google.com', 'https://www.google.com',
'news:comp.lang', 'mailto:test@nowhere.com',
' http://www.google.com',
'bad_http://www.google.com',
'mailtobad:fdsa', 'ftp://ftp.host.net',
'ftpbad:', 'badftp://');

foreach($tests as $v) {
print "'".$v."'" . ' ~ ' .
(preg_match($pattern, $v)
? 'matches'
: 'doesn\'t match')."\n";
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация