繁体   English   中英

SESSION数据在太空中断

[英]SESSION data cutting off at space

(signup_process.php)

$city=cleanup($_POST['city']);
echo $city;

产出:纽约

$_SESSION['city']=$city;
echo $_SESSION['city'];

产出:纽约


问题:

(signup.php)

<form method=post action='signup_process.php'> 

City<input type=text name=city value=<?php echo $_SESSION['city'];?>>

输出:新

City<input type=text name=city value=<?php echo urlencode($_SESSION['city']);?>>

输出:New + York

City<input type=text name=city value=<?php echo urlencode(str_replace('+', '', $_SESSION['city']));?>>

输出:New + York

我试图将数据回显到表单中。

  1. 为什么会话数据在空格后会中断?
  2. 如何删除+号?

您必须将值放在引号中,否则浏览器会将空格后的部分解释为<input>标记的另一个属性。 例如:

<input type="text" name="city" value="<?php echo $_SESSION['city'];?>">

在您的示例中,

<input type=text name=city value=New York>

约克价值之后的下一个属性。

我已经解决了问题,解决方法是对HTML = space使用()

这个解决方案:

str_replace(" ", "&nbsp;", $_SESSION['city'])

该方法可以在

 echo '<input style="font-size:  17px;color: black;" type="text" name="us" class="form-control" disabled="disabled" value='. str_replace(" ","&nbsp;",$_SESSION['username']).' >';

暂无
暂无

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

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