简体   繁体   English

php docent 回显输入的正确值

[英]php dosent echo the right value of a input

I want to concat a string in jquery, but when I post the string I see only a part of the mystringg.我想在 jquery 中连接一个字符串,但是当我发布字符串时,我只看到 mystringg 的一部分。

My html is:我的 html 是:

 <input type="text" style="display:none" name="mystring" id="mystring" value=""/>

I have some variables:我有一些变量:

var ti="ti";
var low="low";
var moderate="moderate";
var high="high";
var title="title";

And I try to concat a string like:我尝试连接一个字符串,如:

var mystringg="";
mystringg+= "<\n"+ti+">";
mystringg+= "\n<LOW> "+low+" </LOW> ";
mystringg+= "\n<MODERATE> "+moderate+" </MODERATE> ";
mystringg+= "\n<HIGH> "+high+" </HIGH> ";
mystringg+="\n</"+title+">";

alert(mystringg); // here print the right value of the string
$('#mystring').val(mystringg);

In php:在 php 中:

$string  = $_POST['mystring'];
echo $string;

When I alert mystringg, I get the right string.当我提醒 mystringg 时,我得到了正确的字符串。 But when I post it in an another php page, I only get a part of the value, actually I get only the value of the variables, not the manual values.但是当我将它发布到另一个 php 页面时,我只得到了一部分值,实际上我只得到了变量的值,而不是手动值。

You are getting the full values.您正在获得完整的值。 The reason you don't think so is because you've wrapped them in tags, although not standard HTML tags.您不这么认为的原因是因为您将它们包装在标签中,尽管不是标准的 HTML 标签。

If you var_dump($_POST['mystring']);如果你var_dump($_POST['mystring']); , you'll see this: ,你会看到这个:

string '<ti><LOW> low </LOW> <MODERATE> moderate </MODERATE> <HIGH> high </HIGH> </title>'

So, the full value is there.所以,全部价值就在那里。

But - when you view the echo of it (as your code does), the tags are being rendered as HTML tags (and thus don't show up), so it looks like this:但是 - 当你查看它的echo时(就像你的代码一样),标签被呈现为 HTML 标签(因此不显示),所以它看起来像这样:

low moderate high

BUT, if you view source, you'll see that in fact it's all there:但是,如果您查看源代码,您会发现实际上它就在那里:

<ti><LOW> low </LOW> 
<MODERATE> moderate </MODERATE> 
<HIGH> high </HIGH> 
</title>

If you want to see the "tags" when you echo them, then echo using htmlspecialchars like so:如果您想在回显时看到“标签”,则使用htmlspecialchars回显,如下所示:

echo htmlspecialchars( $_POST['mystring'] );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM