|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-01-24 16:11 UTC] spoon at nexdot dot net
First, this task can be accomplished with a regex, but it is only _so_ effective. If there was some way to make functions that would take in a string, and return a string that has all links, and all email addresses (2 seperate functions, or one with a set of switches) properly formatted to work as links. The reason it is hard with regex, is becuase it is impossible to search for a link when it can be formatted so many ways. /********** simple **************/ $string = "Hey, check out http://www.spoonified.com, and email me at spoon@nexdot.net"; $linkified = hrefparse($string); echo $linkified; /*******************************/ returns this: Hey, check out <a href="http://www.spoonified.com">http://www.spoonified.com</a>, and email me at <a href="mailto:spoon@nexdot.net">spoon@nexdot.net</a> of course, the link, the main reason regex is bad, could have many things in it, it could point to a file, have a query string in it, have no www, have many PERIODS (multiple subdomains), be https://, and also not be seperated from other text (such as "OMFGwww.spoonified.comRULES"), and the list goes on. Email addresses follow the same conditions i mentioned above (minus a few of course, and plus a few also). Maybe im just overlooking a complex enough regex to do this. I DO know it can be done. Many IRC/Instant Message programs do a wonderful job of it. They take a link, no matter what conditions, or an email address, and will show an active link once sent. Obviously there is a rexeg im too lame to understand, or a better way to accomplish it. (also, you 5.0.xCVS is still having an error on the php4apache2.dll compile, just a sidenote, no comments needed, i think you guys are already aware) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 12:00:01 2025 UTC |
In the source of your bug.php, at the very bottom it has a line: $note = addlinks(preg_replace("/(\r?\n){3,}/","\n\n",wordwrap($comment,72,"\n",1))); addlinks is not defined in the source, so i am assuming it is in prepend.inc (?), but unfortunatley, we cannot view .inc files using source.php, any help?/include/functions.inc (i was forgetting /include) function addlinks($text) { $text = htmlspecialchars($text); $text = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\\s|\\)|\\.\\s|$)/i","<a href=\"\\1\">\\1</a>\\3",$text); # what the heck is this for? $text = preg_replace("/[.,]?-=-\"/", '"', $text); return $text; } WOOOO. PHP.NET RULES!