View Full Version : Converting pure text url to working link
Afrow UK
11-21-2003, 12:13 AM
I am wondering if there is a simple and relatively decent solution to converting e.g.
www.planetquake.com
to
<a href="http://www.planetquake.com" target="_blank">www.planetquake.com</a>
Currently, my parsers will convert and stuff, so I need to convert urls that fit the following:
Do not start with href=" and do not end with "
Start with http:// (][/url) or [url]www. and end with either nothing or a space.
I'm sure this is possible, but I lack the string processing skills to get it working.
-Stu
Afrow UK
11-24-2003, 11:02 PM
If noone can (or will) help me with that, may I ask a solution to this string replacement problem for my bug boards.
$input =~ s|\(.+)\[/img\]|<img src="$1">|gi;
This code will replace hello.jpg with <img src="hello.jpg">
Now here is the problem with my code.
If the user enters...
hello1.jpg
hello2.jpg
...it becomes <img src="ello1.jpghello2.jpg">.
Rather than stopping at the next after , it stops at the last that it can find in the query string.
How can I get it to stop at the next (not last) occurance.
Thanks
-Stu
Jeff Mott
11-25-2003, 03:43 AM
$input =~ s|\[img\](.+?)\[/img\]|<img src="$1" alt="">|gi;The added alt attribute will help the resulting HTML to be valid.
As for your original question, I have a regex to match URIs, but it does not meet your personal requirements, in addition to being long and complicated. Let me know if you want me to post it anyway.
Afrow UK
11-25-2003, 07:28 PM
Thanks for that above code, it works great.
As for [quote]'s I changed the method to this:
if (($input =~ /\[quote=/) and ($input =~ /\[\/quote\]/)) {
$input =~ s|\[quote=(.+?)\]|<table style="border: 1px dashed black; width: 100%"><tr><td style="border: 1px dashed black"><small>Quote: $1</small><hr><small>|gi;
$input =~ s|\[/quote\]|</small></td></tr></table>|gi;
}
I've decided to leave the web url conversion out, but you can post it if you like.
-Stu
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.