我有一个有故事的网站.我可以在多个类别中拥有多种类型的故事,例如:
可以使用以下网址访问这些故事:
www.example.com/action/story-name-action/
www.example.com/romance/story-name-romance/
Run Code Online (Sandbox Code Playgroud)
第一个参数(动作)和第二个(故事名称动作)使用规则重定向.htaccess.这部分工作正常.
最近,我从不同的网站得到了几十个404,这就是我想要做的但我不知道如何:
如果有人输入,例如:/action/story-nme-ction,我想重定向到:action/story-name-action/
有没有一种有效的方法来实现它?
我想为我的产品重写规则.
我想在URL中使用id和名称,用这样的短划线分隔:
123-name表示产品ID = 123和name = name
所以在我的PHP中,我可以获得$ _GET [id],然后使用此ID查询我的数据库,如下所示:
$sql = "SELECT * from Products Where productid = " . $_GET[id];
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的:
RewriteEngine On
RewriteRule ^products/([0-9+])\-([a-z]+)/?$ products.php?id=$2 [NC,L]
Run Code Online (Sandbox Code Playgroud)
但当我把它作为网址时,我得到了404
为什么?
我需要使用不同格式/结构的对象创建一个数组
我有:
$t = object()
$t > user = object()
$t > user > 0 (object) name = 'wilson';
$t > user > 0 (object) first = 'carl';
Run Code Online (Sandbox Code Playgroud)
我需要得到:
$t = array(
name = wilson
first name = phil
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的以及我被困的地方
foreach($t as $a) {
foreach($a as $l) {
$arr[$l->0->name] = $l->0->first; // line 10
}
}
print_r($arr);
Run Code Online (Sandbox Code Playgroud)
现在我收到一个错误:
PHP解析错误:语法错误,意外T_LNUMBER,在第10行的homework1-a-1.php中期待T_STRING或T_VARIABLE或'{'或'$'
我该怎么办才能修复它?
我的网站上有一个gamimng部分,允许用户使用颜色(蓝色,红色和绿色)显示他们的统计数据的快速状态.
我想根据每个用户生成这样的东西.我到目前为止:
<style>
.box2 {
height: 20px;
background: blue;
float:left;
width:120px;
}
.box3 {
height: 20px;
background: green;
float:left;
width:30px;
}
.box1 {
height: 20px;
background: red;
float:left;
width:140px;
}
</style>
<div>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我应该把css直接放在页面中吗?什么是使用PHP实现这个的最佳方法?