You are here: help with regex « PHP Programming Language « IT news, forums, messages
help with regex

Posted by Petra Meier on 03/05/07 15:57

Hello,

I use the following script to parse URI and email:

function parseLinks($sData){
$regexEmail = "/\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-
Za-
z0-9]+)*\.[A-Za-z0-9]+/";
$sData = preg_replace($regexEmail, "<a id='external'
href='mailto:'$0'>$0</a>", $sData);
$regexURI = '#(^|[^\"=]{1})(http://|ftp://|https://|news:)([^
\s<>]+)
([\s\n<>]|$)#sm';
$sData = preg_replace($regexURI, "\\1<a id=\"external\" name=
\"\\2\
\3\">\\2\\3</a>\\4", $sData);
return $sData;

}

it works just fine, unfortunately I parse the links from texts where I
have fullstops, commas, colons and semicolos at the end of URI which
are parsed as part of the URI:

A sentence with a link http://uri.in.senctence.com/foo.html, and a
comma after the link

would be parsed to:

A sentence with a link <a href="http://uri.in.senctence.com/
foo.html,">http://uri.in.senctence.com/foo.html,<a/> and a comma after
the link

I want to have it like this though:

A sentence with a link <a href="http://uri.in.senctence.com/
foo.html">http://uri.in.senctence.com/foo.html<a/>, and a comma after
the link

I already invested a lot of time with these regex and didn't succeed.
Any of you regex-gurus could help me please! :)

Petra Meier

 

Navigation:

[Reply to this 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

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