Re: [PHP] Filtering URLs problem..
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? regular expressions - in particular a 'negative look behind' assertion. here is a page that [trys to] explain it: http://www.mircscripts.org/showdoc.php?type=tutorialid=2409 google given loads of hits for 'negative look behind', hopefully you get somewhere - me I have too little time to right now to go into examples. good luck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Filtering URLs problem..
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? -- Anders Norrbring Norrbring Consulting -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering URLs problem..
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? Skip anything inside tags... then you're last line would come through completely unchanged... -philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering URLs problem..
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.. You might want to consider using vbCode, there is a nice class for PHP here: http://www.phpclasses.org/browse/package/1379.html HTH, cheers. Silvio -- tradeOver | http://www.tradeover.net ...ready to become the King of the World? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering URLs problem..
On 2005-12-20 16:16 Silvio Porcellana [tradeOver] wrote: 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.. You might want to consider using vbCode, there is a nice class for PHP here: http://www.phpclasses.org/browse/package/1379.html HTH, cheers. Silvio Thanks, but I already use PEAR HTML_BBCodeParser for that part.. :) I solved it by a lookbehind, if there isn't a whitespace before the URL, just jump over it. Thanks for the suggestion! -- Anders Norrbring Norrbring Consulting -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering URLs problem..
Anders Norrbring wrote: On 2005-12-20 16:16 Silvio Porcellana [tradeOver] wrote: 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.. You might want to consider using vbCode, there is a nice class for PHP here: http://www.phpclasses.org/browse/package/1379.html HTH, cheers. Silvio Thanks, but I already use PEAR HTML_BBCodeParser for that part.. :) I solved it by a lookbehind, if there isn't a whitespace before the URL, I answered your question stating that a regexp with a negative-lookahead assertion would probably be a good way to go... but it seems my post never arrived ... anyway I think a negative lookahead or lookbehind assertion will cut it. I would just like to add that you might consider looking behind for something a little more specific that a white space (or lack of it); consider what happens when you are given the following HTML snippet: pclick this: bhttp://yourdomain.com/something/b depending on the processing you do to the text prior to linkifying (made that word up!) this may not be relevant. just jump over it. Thanks for the suggestion! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php