-2

我的页面中有以下结构

page.php

<html>
    <head>
        <title>Page title</title>
        <script src="jquery-2.0.3.js"></script>
        <script type="text/javascript">
            function search(value){
                window.location.href="page.php?search=" + value;
            }
        </script>
    </head>
    <body>
        <?php
            if(!empty($_GET['search'])){
                //SQL-statement with WHERE column LIKE $_GET['search']
            } else {
                //Other SQL-statement without WHERE column LIKE $_GET['search']
            }
        ?>
        <h1>Title</h1>
        <input type="text" onKeyUp="search(this.value);" 
               value="<?php echo $_GET['search']; ?>">
    </body>
</html>

正如您所读到的,重要的是,当spacebar按下 a 时,它会_在 the$_GET['search']和 myinput字段中放置一个&nsbp;

4

3 回答 3

0

也许尝试这样的替换:

var new_string = old_str.replace("&nbsp;", "_");
于 2013-10-30T10:23:35.990 回答
0

value' '(单个空格)并且 window.location.href="page.php?search=" + value; 将被 URL 编码,因此空格被转换为&nbsp;(URL 实体)

你必须urldecode($_GET['search']);把它变成一个空格字符。( http://us2.php.net/urldecode )

于 2013-10-30T10:24:34.323 回答
0

尝试这个,

<?php
    if(isset($_GET['search']) && !empty($_GET['search'])){
         $q=urldecode($_GET['search']);// use it in your query
         //SQL-statement with WHERE column LIKE $_GET['search']
    } else {
        //Other SQL-statement without WHERE column LIKE $_GET['search']
    }
?>

读取urldecode()

于 2013-10-30T10:27:21.217 回答