Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/137493-problems-on-str_replace/
Share on other sites

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 />"; 
}

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?

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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.