| | |
nl2br question
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
While fetching, use str_replace to replace "<br />" with "".
ie.,
ie.,
php Syntax (Toggle Plain Text)
str_replace("<br />", "", $data);
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Nav33n's proposal will return a string with no spaces, instead with new lines where the breaks are.
In order to return a string with line breaks, you should replace <br /> with \n , store it in a variable and then return the variable value as evaluated string.
Doing it like this:
The above should validate the variable content whether it contains php code and execute it. So, the \n will actually cause the string to be returned with new lines in it.
In order to return a string with line breaks, you should replace <br /> with \n , store it in a variable and then return the variable value as evaluated string.
Doing it like this:
PHP Syntax (Toggle Plain Text)
$mytext = str_replace("<br />", "\n", $formatted_text); echo "$mytext";
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
@Rhyan, \n will return extra line breaks. For example, If the actual string is
\n will return
PHP Syntax (Toggle Plain Text)
ab bc
PHP Syntax (Toggle Plain Text)
ab bc
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Hm,
Appears you are right.
It really does not replace new line indicator by html equivalent <br /> it only inserts it before the new line indicator. Odd....
So instead using nl2br, you can use str_replace ("\n", '<br />', $string) to get the new lines correctly substituted....
Obviously the decision how would you do it depends on which one is faster.
So, I suppose nl2br should be faster when reverting to plain text...
Appears you are right.
It really does not replace new line indicator by html equivalent <br /> it only inserts it before the new line indicator. Odd....
So instead using nl2br, you can use str_replace ("\n", '<br />', $string) to get the new lines correctly substituted....
Obviously the decision how would you do it depends on which one is faster.
So, I suppose nl2br should be faster when reverting to plain text...
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: cannot write file
- Next Thread: regex
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube






