我无法让我的addslashes函数和html选项值一起玩得很好.我最初的问题是选项中的单引号,但通过解决,我似乎创建了另一个问题,$ titleunit_name只通过第一个单词.
这就是我想要出来的:
baroffice = O'Fallon&Highway K&N
titleunit_name = O'Fallon&Highway K&N
cleantitleunit_name = O \'Fallon&Highway K&N
这就是我得到的:
baroffice = O'Fallon的
titleunit_name = O'Fallon&Highway K&N
cleantitleunit_name = O \'Fallon&Highway K&N
我不知道它是否重要,但值通常来自并被发送回ms sql.
<form method="post" action="formtest.php?" id="searchform" target="" autocomplete="off">
<div id="office">
<font style="font-size:12px; font-weight:bold;" color="#002EB8" face="Verdana">
Closing Office:</font>
<select name="baroffice" style="width:90px">
<?php
$titleunit_name= "O'Fallon & Highway K&N";
$cleantitleunit_name=addslashes("$titleunit_name");
echo "<option value=$cleantitleunit_name name= '$titleunit_name'>";
echo "$titleunit_name</option>";
?>
</select></div><br>
<br><Br>
<input type="submit" name="submit" value="submit" style="position:relative;z-index:3">
<br><Br>
</form>
<?php
$baroffice = str_replace("\'","'",($_POST['baroffice']));
if (isset($_POST['submit']))
{ …Run Code Online (Sandbox Code Playgroud)