【发布时间】:2014-10-19 11:45:19
【问题描述】:
这段代码是这样工作的
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>
【问题讨论】:
-
您发布的那段代码与 URL 的生成有什么关系?或者:你的代码中这个 URL 问题的根源在哪里?
-
只使用str_replace,你为什么要删除那些?你的某一行有文字
appleipod(没有空格)吗? -
我不明白.. PHP 手册:urlencode()、urldecode()、str_replace()、htmlentities()。
-
您要解决的问题是什么?
$_GET已经被解码,所以所有这些要求你替换东西的答案都不起作用。就您的问题寻求帮助,而不是您认为的问题解决方案 - 请参阅X-Y problem。