Page 1 of 1

Convert Line Endings

Posted: Fri Mar 19, 2004 3:02 pm
by AliasBDI
I am displaying a query result with is a TEXT column in a database. It's contents are filled with simply html tags like "<b>". When echoing this record, how can I get it to show as HTML and not the actual tags? Here is the code so far:

Code: Select all

<?php echo $row_articleDETAILS&#1111;'article']; ?>
I tried htmlentities but that did not work.

Re: Convert Line Endings

Posted: Fri Mar 19, 2004 3:05 pm
by TheBentinel.com
What did htmlentities do to "<b>"? When you view source on the page, what did it generate?

it showed...

Posted: Fri Mar 19, 2004 3:11 pm
by AliasBDI
It showed the tags as actual HTML: "blah blah <b>blah..." It did not convert it to bold text. This seems to the backwards than what I want.

i got it...

Posted: Fri Mar 19, 2004 3:13 pm
by AliasBDI
I did the reverse...

html_entity_decode()

Re: it showed...

Posted: Fri Mar 19, 2004 3:15 pm
by TheBentinel.com
AliasBDI wrote:It showed the tags as actual HTML: "blah blah <b>blah..." It did not convert it to bold text. This seems to the backwards than what I want.
Hmmmm.. I would have expected the "<" to be translated to "<". It would display in the browser as "<", but the view source would show <

Do you actually want <B> to make the text bold? If that's all you're shooting for, then just dump the stuff to the browser.

Let me ask it this way: If the database record contains "I'm <i>so</i> glad you <b>boldly</b> took that step", what exactly do you want the browser to display?

this

Posted: Fri Mar 19, 2004 3:35 pm
by AliasBDI
I want it to show like this:

"I'm so glad you boldly took that step"

Posted: Fri Mar 19, 2004 3:39 pm
by Illusionist
then just echo it straight out. Don't pass it through any function, jsut echo it out, and it'll be just like that.

Re: this

Posted: Fri Mar 19, 2004 3:39 pm
by TheBentinel.com
AliasBDI wrote:I want it to show like this:

"I'm so glad you boldly took that step"
Then I think you just want to dump it straight from the database onto the browser. Don't run it through any functions at all. Then I believe you'll have what you want.

ohhh

Posted: Fri Mar 19, 2004 3:46 pm
by AliasBDI
You're right... My mistake - making things complicated. But what about converting line endings? So when a person puts a return at the end of a sentence instead of a <br> tag, I want it to display as a return.

Posted: Fri Mar 19, 2004 3:50 pm
by Illusionist
Imagesame thing..... Echo it stragiht out to the brwoser and it wont show the <br> tag, it'll show as a new line....

Re: ohhh

Posted: Sat Mar 20, 2004 6:51 am
by malcolmboston
AliasBDI wrote:You're right... My mistake - making things complicated. But what about converting line endings? So when a person puts a return at the end of a sentence instead of a <br> tag, I want it to display as a return.
this is how im currently doing it

Code: Select all

$preformatted_text = "A user inserted this text here";
$formatted_text = nl2br($preformatted_text);
works a treat