Chrome 和 Safari 中的文本区域,所有可见换行符发送到服务器
我在尝试使用 Chrome 和 Safari 将数据输入 mysql 数据库时遇到了一些麻烦。当我从这些浏览器中的任何一个输入数据时,发送到数据库的数据都会在文本区域字段的边缘处显示中断。因此,它不再是一长行文本,而是分成几行。
当数据进入数据库时,我正在运行 stripslashes
和 strip_tags
。它在 FF 和 FF 中运行良好。 IE。
请参阅下文了解我的意思:
文本输入字段:
http://www.redcontour.com/query/textarea_field.png
Chrome 和 Chrome 浏览器Safari 数据库条目:
http://redcontour.com/query/Chrome_Safari_db_data.png
FF& IE 数据库条目:
http://redcontour.com/query/FF_IE_data.png
问题是我我并不总是返回数据以供在与最初放入的文本区域框宽度相似的 div 中使用,因此数据没有运行在 div 的整个宽度上看起来很奇怪。
有什么想法吗?
发布更新 - 下面是数据发送到数据库之前的验证,上面的示例是我输入的数据,我在浏览器中的两个实验中没有做任何不同的事情,所以我不知道如何链接中断正在发生。
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
// Check for about.
if (empty($_POST['about'])) {
$a = FALSE;
$message .= '<p>About you description missing.</p>';
} else {
$a = escape_data(strip_tags($_POST['about']));
}
用于输入数据的 HTML 代码。
<textarea class="ed_text_box" name="about" wrap="physical" rows="5" onKeyDown="textCounter(document.details.about,document.details.ed_text_box,500)" onKeyUp="textCounter(document.details.about,document.details.ed_text_box,500)">I'm a traveller at heart, having lived in Portugal and England. Love camping and getting away from it all, whether it's walking the Cornish coast or canoeing in the Brecon Beacons.</textarea>
文本计数器只是阻止用户在字段中放入过多的副本,我在没有它的情况下对其进行了测试,并且遇到了同样的问题。 CSS 也在下面,所以所有信息都可以在这篇文章中找到。
.ed_text_box {width:394px; border:1px solid #CCCCCC; padding:2px 2px 2px 2px; margin:0 0 20px 0; font-size:12px; font-family:Verdana, Arial, SunSans-Regular, Sans-Serif; font-weight:normal; color:#564b47;}
非常感谢任何帮助。
I've ran into a bit of trouble trying to input data into my mysql db using Chrome and Safari. When ever I input data from either of these browsers the data sent into the db is showing breaks where the edge of the textarea field is. So intead of having one long line of text it's broken over a few lines.
I'm running stripslashes
and strip_tags
for when the data goes into the DB. It works fine in FF & IE.
See below to see what I mean:
Text input field:
http://www.redcontour.com/query/textarea_field.png
Chrome & Safari DB entry:
http://redcontour.com/query/Chrome_Safari_db_data.png
FF& IE DB entry:
http://redcontour.com/query/FF_IE_data.png
The problem with this is that I'm not always returning the data for use in a div of similar width to the textarea box it was originally put into so it looks very strange the data not running the entire width of the div.
Any ideas?
POST UPDATED - Below is the validation before the data then gets sent into the db, the example above is data I've inputted and I haven't done anything different in both of the experiments in the browsers, so I don't know how the link breaks are getting in.
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
// Check for about.
if (empty($_POST['about'])) {
$a = FALSE;
$message .= '<p>About you description missing.</p>';
} else {
$a = escape_data(strip_tags($_POST['about']));
}
HTML code for inputting the data.
<textarea class="ed_text_box" name="about" wrap="physical" rows="5" onKeyDown="textCounter(document.details.about,document.details.ed_text_box,500)" onKeyUp="textCounter(document.details.about,document.details.ed_text_box,500)">I'm a traveller at heart, having lived in Portugal and England. Love camping and getting away from it all, whether it's walking the Cornish coast or canoeing in the Brecon Beacons.</textarea>
the text counter just stops users putting too much copy into the field, i've tested it without it and I get the same problem. the css is also below so all info is available in this post.
.ed_text_box {width:394px; border:1px solid #CCCCCC; padding:2px 2px 2px 2px; margin:0 0 20px 0; font-size:12px; font-family:Verdana, Arial, SunSans-Regular, Sans-Serif; font-weight:normal; color:#564b47;}
any help is hugely appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些浏览器很可能响应
尽管 Chrome 和 Safari 都不是 IE,并且您注意到 IE 工作正常,但我怀疑这仍然是您的问题。
Most likely these browsers respond to the
wrap="physical"
attribute on the<textarea />
. According to THIS the attribute is IE-specific and corresponds towrap="hard"
, meaning the line-breaks visible to the user are included in the data sent to the server. What you want is thewrap="soft"
behavior, which I'm quite certain is the default across all browser -- so there would be no need to specify it.Granted neither Chrome nor Safari are IE and you note that IE works fine, but I'd suspect that's your issue non the less.