这段代码就像这样工作
example.com/view.php?category=laptop&model=apple%20ipod
所以我想这样(删除空格)
example.com/view.php?category=laptop&model=appleipod
我该怎么做才能帮我解决这个问题,谢谢
<?
$category = $_GET['category'];
$model = $_GET['model'];
//connect to database
mysql_connect('localhost','user','pass');
mysql_select_db('datanew');
$result = mysql_query("SET NAMES utf8"); //the main trick
$q=mysql_query("select * from data where category='$category' And model='$model' AND TRIM(model) IS NOT NULL");
//Adds one to the counter
mysql_query("UPDATE data SET counter = counter + 1 where category='$category' And model='$model'");
//Retreives the current count
$count = mysql_fetch_row(mysql_query("SELECT counter FROM data"));
$row=mysql_fetch_object($q);
echo mysql_error();
?>
<table class='hovertable'><?php if($row->model):?><tr class=\"style1\"><td width='200'><b>Model:</b></td><td><?php echo $row->model ?></td></tr><?php endif; ?>
<?php if($row->category):?><tr class=\"style1\"><td width='200'><b>Category:</b></td><td><?php echo $row->category?></td></tr><?php endif; ?></table>
答案 0 :(得分:1)
<?php
$model = str_replace(" ", "", $_GET['model']);
?>
答案 1 :(得分:1)
(Auto. urldecode)
使用str_replace(" ", "", $model);
但我建议在构建网址时进行工作。
如果您要替换构建网址的空白,则可以使用str_replace(" ", "", $myModelName);
。
答案 2 :(得分:0)
使用replace_str替换所有空格
http://php.net/manual/en/function.str-replace.php
<?php
$model = str_replace(" ", "", $_GET['model']);
?>