Thread: mysql & php new line problem
Results 1 to 7 of 7
Related
-
Problem in mysql statement and if condition Forum: PHP Forum
Replies: 2 -
mysql query / function problem.... Forum: Databases
Replies: 7 -
MySql problem --with -- mysqlimport and TIMESTAMP Forum: Databases
Replies: 3 -
Perl dbi with mysql problem Forum: CGI Perl Forum
Replies: 1 -
I have a Problem with text line spacing Forum: HTML Forum
Replies: 1
-
03-10-2006, 07:49 AM #1
mysql & php new line problem
I started learning php and mysql to create dynamic pages with a admin interface. I created it with the textarea tag and put the text into mysql and it looks like this when i see it in phpmyadmin
This is a test
this is line 2
this is line 3
but when outputting in php i get it all in the same row.
i fetch the text from mysql and put it into a variable. somewhere along the line the new lines or linefeeds dissepear,
does anyone have an awnser, i use php5 and mysql5
thanx in advance/ Mattias
-
03-11-2006, 07:54 PM #2
Re: mysql & php new line problem
Hi, Mattias, and welcome to the forum!
The reason you're getting that is there are hidden new line characters "/n" (without the quotes) embedded in your text. To get rid of them and have your text display correctly in an HTML document, you need to use str_replace. For example:
PHP Code:$line = str_replace("\n","\n<br>","$line");
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
-
03-13-2006, 01:49 AM #3
Re: mysql & php new line problem
Hi.
Thanks!
It worked great.
-
07-08-2011, 08:08 AM #4
Re: mysql & php new line problem
And how will be if i want the output like
PHP Code:echo "<a href='....' title='$line'>....</a>";
-
07-15-2011, 09:16 AM #5
Re: mysql & php new line problem
You can also use nl2br for this:
PHP Code:echo nl2br($line);
PHP Code:$line = str_replace("\n", "", $line);
-
07-20-2011, 01:52 AM #6
Re: mysql & php new line problem
Firstly I would like to suggest you to learn the PHP codes first. Then you do not face such kind of problem. some of the code of php is different then html. So I would like to suggest you to learn the codes from some good tutorial like w3schools.
-
07-21-2011, 08:31 AM #7
Re: mysql & php new line problem
That statement has always bugged me. PHP and HTML are two completely different things. ALL of PHP code is different from HTML. HTML does only one thing: displays and formats data. It does not interpret the data nor do anything with servers. PHP on the other hand, gets the data from its source, determines what should happen with the data, and then creates the HTML code to display it.
This is always good advice. I still use the tutorials as reference at times.
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum