1. PHP这段代码怎么写
<html>
<head>
<meta ;charset=utf-8" />
<title>;测试</title>
</head>
<body>
<?php
if($_POST && $_POST['age']){
$age = intval($_POST['age']);
if($age>=1 && $age<=17){
echo "你正处于少年时期,好好努力";
}else if($age>=18 && $age<=29){
echo "你处于青年时期,努力奋斗";
}else if($age>=30 && $age<=50){
echo "你处于壮年时期,处于事业巅峰";
}else{
echo "你的年龄我无法判断";
}
}
?>
<form action="" method="post">
<p><span>;年龄</span><input name="age" type="text"/></p>
<p><input type="submit" value="提交" name="submit"/></p>
</form>
</body>
<html>
2. 这样的PHP代码怎么写
这样就行了。
也可以上楼上说的用反序列化函数unserialize()。这种形式一般是放在数组库的 $str ='a:7:{s:9:"frame_set";s:2:"lc";s:8:"allframe";a:2:{s:5:"dleft";a:8:{i:0;s:7:"profile";i:1;s:7:"applist";i:2;s:10:"friendlist";i:3;s:9:"footprint";i:4;s:5:"doing";i:5;s:4:"mtag";i:6;s:5:"share";i:7;s:6:"player";}s:8:"dcontent";a:7:{i:0;s:4:"feed";i:1;s:8:"albumone";i:2;s:4:"blog";i:3;s:8:"albumall";i:4;s:6:"thread";i:5;s:11:"forumstatus";i:6;s:4:"wall";}}s:9:"effectall";a:0:{}s:9:"blockname";a:0:{}s:5:"music";a:0:{}s:5:"block";a:1:{s:4:"body";a:1:{s:0:"";a:1:{s:16:"background-image";s:95:"background-image:url( http://127.0.0.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif)";}}}s:6:"cursor";N;}background-image:url( http://1ds.0.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif)";}}background-image:url( http://127.sdf.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif)";}}background-image:url( http://1jhgk0.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif)";}}'; if(preg_match_all('/url\((. ?)\)/', $str, $matches)) { foreach($matches[1] as $val) { echo $val; echo ""; } } 测试结果: http://127.0.0.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif http://1ds.0.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif http://127.sdf.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif http://1jhgk0.1/pic/f7fc7f0ea9e5b753707ae20b87b8478e_b.gif 不会再问:QQ:1350630107,接5000元以上大型项目,二次开发等。
3. 一段php代码该怎么写
根据你的描述,好像是显示产品的一个格式,$a, $id,$num,$money分别是对应各个产品的属性,$count则是计算所有产品的总价值,那么php代码可以这样写:$id = explode('|', '3171|2486');$num = explode('|', '8|5');$money = explode('|', '1|1');$count = 0;$totalNum = count($a);echo count($a) . "";$str = "{";for ($i = 0; $i /* $str .= '\"'; $str .= $a[$i]; $str .= '\":{\"id\":'; $str .= $id[$i]; $str .= ','; $str .= '\"num\":'; $str .= $num[$i]; $str .= ',\"money\":'; $str .= $money[$i]; $str .= '},'; */ $str .= sprintf('\"%d\":{\"id\":%d,\"num\":%d,\"money\":%d},', $a[$i], $id[$i], $num[$i], $money[$i]); $count += ($num[$i] * $money[$i]);}$str .= '\"Count\":';$str .= $count;$str .= '}';echo $str; 追问: json_encode json_decode 楼下说用这种方法,我也记得好想是有个命令可以把数组直接变成这种格式的 追答: 使用json_encode的话,以下是最简单的一个示例: 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);echo json_encode($arr);?>输出{"a":1,"b":2,"c":3,"d":4,"e":5}要使用的话,同样也是在for循环中构造,一样的结果,且只能构造{\"id\":3171,\"num\":8,\"money\":1}这个元素集合段,其中\符号也不会出现 追问: addslashes 这个函数可以添加 斜杠的 你QQ多少,我想再问一下 评论0 0 0。
4. PHP代码编写
<?php
function modelup($len){
$str="";
for($i=0;$i<$len;$i++){
for($n=$len;$n>$i;$n--){
$str.=" ";
}
for($j=0;$j<$i+1;$j++){
$str.=" * ";
}
$str.="<br>";
}
return $str;
}
function modeldown($len){
$str="";
for($i=0;$i<$len;$i++){
for($n=0;$n<$i+2;$n++){
$str.=" ";
}
for($j=5;$j>$i;$j--){
$str.=" * ";
}
$str.="<br>";
}
return $str;
}
function model($len){
return modelup($len).modeldown($len);
}
echo model(6);
?>
输出结果
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
5. PHP怎么写类,一般什么时候用,要代码哦
写类就用Class关键字来声明。
比如:
class Cart {
var $items; // 购物车中的物品
//构造函数,用来初始化一个类
function Cart() {
$this->items = array();
}
// 将 $num 个 $artnr 物品加入购物车
function add_item($artnr, $num) {
$this->items[$artnr] += $num;
}
// 将 $num 个 $artnr 物品从购物车中取出
function remove_item($artnr, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} elseif ($this->items[$artnr] == $num) {
unset($this->items[$artnr]);
return true;
} else {
return false;
}
}
}
类的用处很广,是面向对象编程的基础,一般在你要封装一个对象的时候使用。
6. 下面这段代码用PHP语言怎么写
$rows = explode(',', $str);
echo '';
foreach($rows as $row){
$cols = explode(' ',$row);
echo '';
foreach($cols as $col){
echo '' . $col . '';
}
echo '';
}
echo '';