Why there are 6 more spaces at the beginning when editing is displayed in textarea

Source: Internet
Author: User
Use PHP to write your own blog program on Sina app engine. When you create or update an article, use textarea to accommodate the content of the article, and temporarily save the article content to the database as plain text.

The form is like this (in write_article.php):

The SQL statement that saved the article is this (in save_article.php).

$content = $_POST["article_text"];// update article$sql = "update article set title=\"$title\",type=\"$category\",content=\"$content\",summary=\"$summary\",updatetime=\"$datetime\" where id=$id";... ...// save new article$sql = "insert into article values ($id, \"$category\", \"$title\", \"$author\", \"$summary\", \"$content\", \"$datetime\", \"$datetime\", $hits)";

However, when the article is updated (in write_article.php), it is found that there are always six more spaces at the beginning of the text displayed in textarea. Delete the space, and then submit the article. Wait until you edit the article and find that textarea starts with six more spaces.

However, when reading the article , it is found that there are no extra spaces at the beginning of the article.

Think of the solution, so to all of you for help, this extra space is how to go?

Reply content:

Use PHP to write your own blog program on Sina app engine. When you create or update an article, use textarea to accommodate the content of the article, and temporarily save the article content to the database as plain text.

The form is like this (in write_article.php):

The SQL statement that saved the article is this (in save_article.php).

$content = $_POST["article_text"];// update article$sql = "update article set title=\"$title\",type=\"$category\",content=\"$content\",summary=\"$summary\",updatetime=\"$datetime\" where id=$id";... ...// save new article$sql = "insert into article values ($id, \"$category\", \"$title\", \"$author\", \"$summary\", \"$content\", \"$datetime\", \"$datetime\", $hits)";

However, when the article is updated (in write_article.php), it is found that there are always six more spaces at the beginning of the text displayed in textarea. Delete the space, and then submit the article. Wait until you edit the article and find that textarea starts with six more spaces.

However, when reading the article , it is found that there are no extra spaces at the beginning of the article.

Think of the solution, so to all of you for help, this extra space is how to go?

You</code>后面有空格和换行,所以会这样。内容顶着<code><textarea></code>写,</p><p>保存的时候用 <code>$content =trim( $_POST["article_text"] );</code></p><p>就可以了~</p> <p class="answer fmt" data-id="1020000000332993"> <p>改成:</p><pre class="brush:php;toolbar:false"><code><textarea rows="20" cols="80" name="article_text"><?php if($op == "update"){echo $content;} ?>

Note that there are no extra things in textarea, and you have lines and spaces in your original code.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.