lukelee Posted December 18, 2008 Share Posted December 18, 2008 Here is my code, I set the about_maxi class width 200px; it works fine without the function format_html2, it auto change a line when reach the end of the box. but after i add function format_html, it write over the box, it doesnt stop when reach the end of the box, does anyone know how to fix it? <div class="about_maxi"> <?php $query = mysql_query("SELECT * FROM max WHERE id='1'"); while($row = mysql_fetch_array($query)) { $content = $row['content']; function format_html2($content) { $content = "<p>" . str_replace("\r\n", "<br/>", $content) . ""; $content = "" . str_replace("<br/><br/>", "</p><p>", $content) . ""; return "" . str_replace("<br/><li>", "<li>", $content) . ""; } echo format_html2("$content"); }?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/ Share on other sites More sharing options...
RichardRotterdam Posted December 18, 2008 Share Posted December 18, 2008 why would you define a function in a loop that makes no sence. what does it do when you just echo the content? $query = mysql_query("SELECT * FROM max WHERE id='1'"); while($row = mysql_fetch_array($query)) { $content = $row['content']; echo $content."<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/#findComment-718603 Share on other sites More sharing options...
lukelee Posted December 18, 2008 Author Share Posted December 18, 2008 if i echo the content, it just display the content in the database. this is a front end, there is an back end, i can edit the content in the back end, so i want to display all those /r/n, br, p i have entered in the back end. is there proper way to use those codes? Quote Link to comment https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/#findComment-718626 Share on other sites More sharing options...
RichardRotterdam Posted December 18, 2008 Share Posted December 18, 2008 a couple of questions. 1. how are you entering the content into the database? 2. how does the content look in the database if you use phpmyadmin or mysql querybrowser or what ever you use to view your database data? 3. does the data in your database fields contain the characters \r\n? 4. have you concidered using a RTE(Rich Text Editor) for content input in your backend? 5, what do you mean with: it doesnt stop when reach the end of the box Quote Link to comment https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/#findComment-718639 Share on other sites More sharing options...
lukelee Posted December 18, 2008 Author Share Posted December 18, 2008 i set the box 200px wide, when the sentence is longer than 200px, it should auto change a new line, but it doesnt. 1: here is the code in my cms: $about_maxi = $_POST['about_maxi']; $query1 = mysql_query("UPDATE max SET content='$about_maxi' where id='1'"); <textarea name="about_maxi" class="form_size1"><?php echo $row['content']; ?></textarea> 2: they looks normal in phpmyadmin, if i enter 'enter', they change a line, i enter space, they leave a space between words. 3: no, /r/n doesnt in my database. 4: i dont know what is rich text editor. Quote Link to comment https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/#findComment-718651 Share on other sites More sharing options...
RichardRotterdam Posted December 18, 2008 Share Posted December 18, 2008 i set the box 200px wide, when the sentence is longer than 200px, it should auto change a new line, but it doesnt. here is your answer to your problem. you should use css to set the width of your box i set the box 200px wide, when the sentence is longer than 200px, it should auto change a new line, but it doesnt. 1: here is the code in my cms: $about_maxi = $_POST['about_maxi']; $query1 = mysql_query("UPDATE max SET content='$about_maxi' where id='1'"); <textarea name="about_maxi" class="form_size1"><?php echo $row['content']; ?></textarea> You have a security leak there even if you're the only one using it you should use mysql_real_escape_string() to prevent sql injections 2: they looks normal in phpmyadmin, if i enter 'enter', they change a line, i enter space, they leave a space between words. 3: no, /r/n doesnt in my database. if there is no /r/n stored in the database that function you had wouldn't do anything for you to begin with 4: i dont know what is rich text editor. a rich text editor is something like you see here when you post a message. it will make you enter text like msword does or any office app. tinymce and fckeditor are two examples of rich text editors. Quote Link to comment https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/#findComment-718653 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.