php无法从url中获取带有特殊字符或空格的mysql结果


php cannot GET mysql results from url with special characters or spaces?

我已经尝试解决这个问题2天了,现在没有效果。

基本上,我正在尝试$_GET结果从mysql基于任何是在URL从前一页传递。

url如下:http://mydomain.com/manufacturer/abc

实现这个URL,我使用.htaccess工作良好。

但是如果url有empty space-或任何其他特殊字符,我的php文件将不会从mysql数据库获取结果。

所以这不起作用:

http://mydomain.com/manufacturer/a-b-c

http://mydomain.com/manufacturer/a b c

http://mydomain.com/manufacturer/a+bc

等等……

我正在使用smarty,到目前为止,这是一个非常直接的过程,但现在它已经到了这个地步,它已经被证明是有点困难。

我的PHP文件是这样的:

if (isset($_GET['man'])) {
$man = $_GET['man'];
if( ! $stmt = $db_conx->prepare("SELECT id, man, product_name FROM `$TabelName` WHERE `man` = ?") ) {
  die( $db_conx->error );
}
$stmt->bind_param('s', $man);
if ( ! $stmt->execute() ) {
  die( $stmt->error );
}
$stmt->bind_result($id, $man, $product_name);
$stmt->store_result();
while($stmt->fetch()) {
    $value[] = array('id'=>$id, 'man'=>$man, 'product_name'=>$product_name);
}
}

// Assign this array to smarty...
$smarty->assign('man', $value);

// Assign this array to smarty...
$smarty->assign('$man', $value);
}

这是我的htaccess文件:

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^manufacturer/([a-zA-Z0-9]+)$ manufacturers.php?manu=$1
RewriteRule ^manufacturer/([a-zA-Z0-9]+)/$ manufacturers.php?manu=$1

我尝试了urlencodeurldecode的每一种可能的方式,似乎没有工作。

有人能就这个问题提出建议吗?

Thanks in advance

试试这个:

RewriteRule ^manufacturer/(.*)/?$ manufacturers.php?manu=$1

注意/?,你不需要第二条规则,这个东西为你做了

DO

RewriteRule ^manufacturer/(.+)/?$ manufacturers.php?manu=$1