Convert Line Endings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Convert Line Endings

Post 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.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: Convert Line Endings

Post by TheBentinel.com »

What did htmlentities do to "<b>"? When you view source on the page, what did it generate?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

it showed...

Post 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.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

i got it...

Post by AliasBDI »

I did the reverse...

html_entity_decode()
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: it showed...

Post 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?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

this

Post by AliasBDI »

I want it to show like this:

"I'm so glad you boldly took that step"
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: this

Post 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.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

ohhh

Post 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.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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....
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: ohhh

Post 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
Post Reply