Reply to Re: Find urls in plain text files

Your name:

Reply:


Posted by Salve Hεkedal on 11/03/07 09:05

On 2007-11-02, Carl <c.groner@gmail.com> wrote:
> "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";
> }

Thank you, Carl, for the script.

But the regexp there is as simple at I could have written myself. What
I need is something that can find urls in a text file, and convert them
to links. And by urls I mean, as I wrote in OT: http://something.org as
well as for example www.someother.anytopdm and the url in the original
text may be in parantheses or for example at the end of a sentence, so
it'll have a . in the end. So on..

Christoph Burschka's is still the most promising, but I haven't had time
to understand and to try it out yet.

Salve

[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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация