Re: Filtering URLs problem..

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

 



I didn't fully test this; but it should get you started.

$types= array('http', 'ftp', 'https', 'mms', 'irc');

$pattern= "%<a\040href\040*=['"]$types://((www.)*[\w/\.]+)['"]>.+</a>%i";  // the "i" makes it non case sensitive

if(preg_match($pattern, $URL_str, $match)){

	$URL= match[1];
}

else{

	User did not enter a complete link; do the simple thing
}



Anders Norrbring wrote:

I'm writing a filter/parsing function for texts entered by users, and I've run into a problem... What I'm trying to do is to parse URLs of different sorts, ftp, http, mms, irc etc and format them as links, that part was real easy..

The hard part is when a user has already entered a complete link..
In short:

http://www.server.tld/page.html
should be converted to:
<a href='http://www.server.tld/page.html'>http://www.server.tld/page.html</a>

That part works fine, but if the user enters:

<a href='http://www.server.tld/page.html'>click here</a>

it all becomes a mess...  Can somebody please make a suggestion on this?

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