Discussion
Hey all,
I'm currently building a little database backed web page.
Part of it needs 'friendly formatting' (basically something along the lines of formatting codes here)
The fixed things like replacing a carrige return with a <br> and a [bold] with <b> are easy, I'm using the following code.
$cont=~s/\n/<br>/g;
Problem comes with links and images, how would I do something like above but with a link. So they simply enter something like [link=whatever.com]This is what is displayed[/link] to be replaced with <a href="whatever.com">This is what is displayed</a>
If someone can post a quick answer it'd be a massive help.
Thanks.
Edited because I forgot about PH code might make this hard to post!
>>> Edited by rpguk on Sunday 23 November 00:15
>>> Edited by rpguk on Sunday 23 November 00:17
I'm currently building a little database backed web page.
Part of it needs 'friendly formatting' (basically something along the lines of formatting codes here)
The fixed things like replacing a carrige return with a <br> and a [bold] with <b> are easy, I'm using the following code.
$cont=~s/\n/<br>/g;
Problem comes with links and images, how would I do something like above but with a link. So they simply enter something like [link=whatever.com]This is what is displayed[/link] to be replaced with <a href="whatever.com">This is what is displayed</a>
If someone can post a quick answer it'd be a massive help.
Thanks.
Edited because I forgot about PH code might make this hard to post!
>>> Edited by rpguk on Sunday 23 November 00:15
>>> Edited by rpguk on Sunday 23 November 00:17
Richard,
This is a bit messy, but here goes:
$cont=~s/\[link/\<a href/g;
$cont=~s/\]/\>/g;
$cont=~s/\[/\</g;
The important thing you need to remmeber to use the \ break char whenever you reference the [ or ] chars, since Perl will try an evaluate it as a regex.
Steve
>> Edited by fatsteve on Sunday 23 November 01:24
>> Edited by fatsteve on Sunday 23 November 01:26
This is a bit messy, but here goes:
$cont=~s/\[link/\<a href/g;
$cont=~s/\]/\>/g;
$cont=~s/\[/\</g;
The important thing you need to remmeber to use the \ break char whenever you reference the [ or ] chars, since Perl will try an evaluate it as a regex.
Steve
>> Edited by fatsteve on Sunday 23 November 01:24
>> Edited by fatsteve on Sunday 23 November 01:26
Richard you are very welcome.
IMHO Perl is the bastard of all languages. My background is J2EE and also Unix sysadmin so my structured language skills and scripting (shell etc) skills are generally good. However, Perl always has me scratching my head!!
I'm trying again to learn it because I've got a SlimServer MP3 streamer (www.slimdevices.com) and the whole lot is open source so can be fettled with as your needs be.
Steve
IMHO Perl is the bastard of all languages. My background is J2EE and also Unix sysadmin so my structured language skills and scripting (shell etc) skills are generally good. However, Perl always has me scratching my head!!
I'm trying again to learn it because I've got a SlimServer MP3 streamer (www.slimdevices.com) and the whole lot is open source so can be fettled with as your needs be.
Steve
I can't believe I registered just for this
here's a 1 line way of doing it....
@array = split(/([link=)|([)|(])/, "[link=whatever.com]This is what is displayed[/link]");
$array[4] now contains the url
$array[8] contains the text to display.
Col.
Sad I know
>> Edited by cmt on Monday 24th November 16:47

here's a 1 line way of doing it....
@array = split(/([link=)|([)|(])/, "[link=whatever.com]This is what is displayed[/link]");
$array[4] now contains the url
$array[8] contains the text to display.
Col.
Sad I know

>> Edited by cmt on Monday 24th November 16:47
cmt said:
I can't believe I registered just for this ![]()
here's a 1 line way of doing it....
@array = split(/([link=)|([)|(])/, "[link=whatever.com]This is what is displayed[/link]");
$array[4] now contains the url
$array[8] contains the text to display.
Col.
Sad I know![]()
>> Edited by cmt on Monday 24th November 16:47
Nice one thanks!

And of course welcome to Pistonheads
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff