在URL php中显示搜索词


Display search term in URL php

我只想在url中显示我的搜索词。不知怎么的,我拿不到。

<?php $string = stripcslashes(isset($_GET['string']));?>
<form action="index.php?string=<?php echo $string;?>" method="post">
    <input name="string" type="text" class="inputbox" id="String" 
    value="<?php echo stripcslashes(isset($_REQUEST["string"])); ?>" 
    size="40" style="width:250px"/>
</form>

此外,在我进行搜索之后,在我的搜索字段中总是显示一个1。我确信这就是把事情搞砸的原因。

代码<?php $string = stripcslashes(isset($_GET['string']));?>将返回1或0。

你必须这样做。。

<?php
if(isset($_GET['string']))
{
$string = stripcslashes($_GET['string']);
}
?>
<form action="index.php?string=<?php echo $string;?>" method="post"><input name="string" type="text" class="inputbox" id="String" value="<?php echo $string; ?>" size="40" style="width:250px"/></form>

isset()函数返回布尔值,而不是变量本身的值。

从手册页面:

boolisset(混合$var[,混合$…])

如果您试图检查变量$_GET['string']是否已定义,然后将其值设置为等于stripcslashes($_GET['string']),则可以使用三元语句执行以下操作:

$string = (isset($_GET['string'])) ? stripcslashes($_GET['string']) : '';
<?php $string = (isset($_GET['string']))?stripcslashes($_GET['string']):'';?>