Formatting a value retirved from database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
anujphp
Forum Commoner
Posts: 25
Joined: Wed Nov 05, 2008 10:12 am

Formatting a value retirved from database

Post by anujphp »

hello
I have stored a paragraph in mysql database and when i try to retrive it and sisplay i want to format the paragrapg...
The paragraph is like this

1.some text 2.again some text 3.again some text 4.again some text


I want my output to be like this

1.some text
2.again some text
3.again some text
4.again some text

and so on

i am able to retrive the praragrapg in a variable like the variable is $paragraph
now i dont no how to cut the line after a number and point(fullstop)

Please Help me guys...its urgent
THANKING YOU IN ADVANCE
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: Formatting a value retirved from database

Post by Hannes2k »

Hi,
you can use preg_replace.

Reg-Ex: "([0-9]+)." replace with "<br />$1."
Last edited by Hannes2k on Wed Nov 19, 2008 8:34 am, edited 1 time in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Formatting a value retirved from database

Post by Eran »

Is it possible this text originated in a textarea? if that's the case it has line-breaks which can be converted to html breaks using nl2br().
anujphp
Forum Commoner
Posts: 25
Joined: Wed Nov 05, 2008 10:12 am

Re: Formatting a value retirved from database

Post by anujphp »

yes the text originate in text area,how to convert line break into html code,cam you please give me the code
anujphp
Forum Commoner
Posts: 25
Joined: Wed Nov 05, 2008 10:12 am

Re: Formatting a value retirved from database

Post by anujphp »

THANKS A LOT


I am able to solve the issue.thanks once again.
As suggested by you i have used the function nl2br and able to get the result as i wanted.
Post Reply