dotelauv682684 2013-04-02 17:45
浏览 112
已采纳

如何保持文本缩进与<textarea>中写入的用户相同

i am using php.my project is to build a forum...everything is fine and ok except onething...there is a <textarea> on top of my site,through which user can ask their question..now am using insert into command to insert whatever user has wriiten in textarea and select command to fetch the posts from database and the display it using echo command

problem : unable to keep the user's text indentation intact

suppose user has written

 #include<stdio.h>
 #include<conio.h>
 int main()
 {
    ...and so on;
  }

this code in the text area,while am displaying it through echo then the output is like

#include<stdio.h>#include<conio.h>int main(){...and so on;}

so my question is how can i keep the text indentation of user intact

edit 1:my insertion code

<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ;
$myemail=$z;
$sem=$_POST['semester'];
$course=$_POST['course'];
$title=$_POST['title'];
$desc=$_POST['question'];
$date=date('Y-m-d H:i:s');
$sem = mysqli_real_escape_string($link, $sem);
$course = mysqli_real_escape_string($link, $course);
$title = mysqli_real_escape_string($link, $title);
$desc = mysqli_real_escape_string($link, $desc);
$sql =  "INSERT INTO wbut_forum_posts SET post_title='$title',post_desc='$desc',course='$course',semester='$sem',post_by='$myemail',post_date='$date'";
if (!mysqli_query($link,$sql))
{
include_once "wall.html.php";
echo "<script language=javascript> alert(\"SOMETHING WENT WRONG, TRY AGAIN LATER !!!\");</script>"; 
exit();
}
else
{
include_once 'wall.html.php';
echo "<script language=javascript> alert(\"YOUR POST SUCCESSFULLY HAS BEEN POSTED\");        </script>";
exit();
}
  • 写回答

5条回答 默认 最新

  • duanmao1919 2013-04-02 19:03
    关注

    Instead of using a straight text area, try a WYSIWYG editor like tinyMCE, after playing with the settings a bit you will be able to get it to create the HTML of what the users enter, so you can get line breaks to convert to <br> tags and tabs to convert to &nbsp;(x4) or x8 or whatever you want. You can also remove all the controls to so it won't necessarily look like a WYSIWYG editor.

    EDIT: WYSIWYG (What You See Is What You Get) - tinyMCE (http://www.tinymce.com/) is one such editor. You can follow the directions on their site, but it basically loads from JS and overrides your text areas with their editor. When the user clicks save or whatever (you tell tinyMCE via JS that the user is done) it will take their text as you see it and convert it to html, that converted text is what you would store in your DB. Since it's html being stored, all the line breaks and white spaces are preserved. A tool like this does require some JS skills to implement, try it and see what problems you come up against. This is kind of an overkill solution. But if you get tinyMCE properly set up it will give you complete control of what gets stored in your DB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序