mhouldridge
asked on
nl2br in Perl? - Need to format output and add newlines
Experts,
I am outputting a longtext field from my db to html. I need to show line breaks as the output is one continuous string.
I know in PHP you can use nl2br which adds <br> however I cant find a function in Perl to do this.
Please help.
I am outputting a longtext field from my db to html. I need to show line breaks as the output is one continuous string.
I know in PHP you can use nl2br which adds <br> however I cant find a function in Perl to do this.
Please help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Store each line in a variable and add <br> at the end using regular expression
$ine=~s/(.)+/$1<br>/g;
now print each line in a HTML file
$ine=~s/(.)+/$1<br>/g;
now print each line in a HTML file
ASKER
Hi,
Thanks for the comments. How would I store each line as a variable from a longtext field within a database. I could understand how this would be done from a text file, reading line by line, but I dont understand how I would read a line of a longtext field?
Thanks for the comments. How would I store each line as a variable from a longtext field within a database. I could understand how this would be done from a text file, reading line by line, but I dont understand how I would read a line of a longtext field?
ASKER
Sorted now. thanks!
$longTextFile =~ s/n/<br>/g;
Here longTextFile is the scalar containing your output.
Cheers