Reply to Re: php, mysql $ html probl

Your name:

Reply:


Posted by Hilarion on 08/22/05 17:03

> i use textarea for input of information
> in textarea usar can press enter to write to next line
> i then insert that into mysql (field type is 'text')
> when php reads it from mysql - the line breaks are missing (because
> html breaks to next line when it sees <br> obveously). how do i solve
> the problem? i thought parsing before inserting into mysql or when i
> read from mysql would do the trick? how do i detect line break?


When otputing the text you retrieve from database, use htmlspecialchars and
nl2br functions. Do not parse the text you insert into DB.

echo nl2br( htmlspecialchars( $text_from_db ) );

This way you'll get exactly what user wrote in your DB (and will not
have to check if your parsing is OK or not) and still will be able
to output it as intended. If you want to allow users to use some
HTML, then you'll have to replace "htmlspecialchars" function
with your own function which would strip forbidden tags (or replace
some custom tags - like "[b]" instead of "<b>" - to HTML).


Hilarion

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация