Gossamer Forum
Home : General : Perl Programming :

making href

Quote Reply
making href
can't find previous post about this but i had a mod that was making a href and storing in the database. i now prefer to store the data without the html tags, then add the tags when i'm reading and printing the record.

this is the code i used before:
$text =~ s/\b(http:\/\/\S+[^-.,\"\';: ])\b/<a href="$1">$1<\/a>/g;

that worked, and the href stuff was written to file. now that is not written to the file. here's the code that reads the file and i'm trying to add the tags before printing but they're not being added:
Code:
open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in displaying record. unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!");
@text = <TEXT>;
close TEXT;
$text = join "",@text;
$text =~ s/\b(http:\/\/\S+[^-.,\"\';: ])\b/<a href="$1">$1<\/a>/g;
print $text;
thanks!
Quote Reply
Re: [delicia] making href In reply to
Hi,

This seems to work fine with me in a test case:

Code:
$test =~ s|\b(https?\://\S+[^-.,\"\';:])\b|<a href="$1">$1</a>|g;

Maybe give this a go:

Code:
open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in displaying record. unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!");
while (<TEXT>) {
s|\b(https?\://\S+[^-.,\"\';:])\b|<a href="$1">$1</a>|g;
$text .= $_;
}
close TEXT;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] making href In reply to
thank you. the second one worked! the only think it didn't do was preserve my line breaks.


please review your wish list to be sure it's correct!

Last edited by:

delicia: Feb 17, 2017, 6:36 AM
Quote Reply
Re: [delicia] making href In reply to
Glad to hear it :)

Quote:
please review your wish list to be sure it's correct!

Thanks - just done that. Need to remember to update that a bit more often! (especially after Christmas Angelic)

With regards to the line breaks - thats because its doing a <while> loop, so the newlines are not transferred. Try it with:

Code:
open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in displaying record. unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!");
while (<TEXT>) {
s|\b(https?\://\S+[^-.,\"\';:])\b|<a href="$1">$1</a>|g;
$text .= "$_\n";
}
close TEXT;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] making href In reply to
didn't work Frown lhave to go to physical therapy. will work on this later
Quote Reply
Re: [delicia] making href In reply to
The code didn't work? Or the tweak for the newline?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] making href In reply to
the link works but the newline doesn't
Quote Reply
Re: [delicia] making href In reply to
Maybe you want <br> instead of \n on:

Code:
$text .= "$_\n";

Hard to tell without seeing how you convert new lines into <br> normally

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] making href In reply to
that worked! duh, i should have thought a little.
Quote Reply
Re: [delicia] making href In reply to
hehe good to hear! Angelic (and don't worry, I do stuff like that all the time - sometimes a little break is all you need, or some coffee =))

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!