php中关于date中的周次

for ($i = 1990; $i <= 2025; $i++) {
	echo $i . '年第一天是星期' . date('w', strtotime($i . '-01-01')) . '====第'  . date('W', strtotime($i . '-01-01')) . '周&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $i . '年最后一天是星期' . date('w', strtotime($i . '-12-31')) . '====第'  . date('W', strtotime($i . '-12-31')) . '周<br />';
}

clipboard

 

可以看到:
                年初的时候,如果第一天是周1,周2,周3,周4这几天,那么用date(‘W’,time())会解析出是这年的第一周
                                     如果第一天是周5,周6,周日这几天,那么用date(‘W’,time())会解析出是上一年的最后一周
                年末的时候,如果最后一天是周1,周2,周3这几天,那么用date(‘W’,time())会解析出是下一年的第一周
                                     如果 最后一天是周4周5,周6,周日这几天,那么用date(‘W’,time())会解析出是这年的最后一周

stdClass object的处理

php取回的json数据是stdClass,要将数据处理成数组,需要用get_object_vars函数,但是该函数只能将第一级对象转为数组

例子:
$back_info = file_get_contents(“http://xxxx/act/cps_api/gamelist/index/?game_ids=” . $ids);
$back_temp = json_decode($back_info);
$back = get_object_vars($back_temp);
foreach ($back as $k => $v) {
print_r($k);
echo “<br />”;
print_r($v);
exit;
}
输出:
97<br />stdClass Object
(
    [game_name] => 神仙道
    [server_info] => stdClass Object
        (
            [894] => stdClass Object
                (
                    [server_number] => 双线94区
                    [server_name] => 九鼎记事
                    [game_url] => http://xxxx/webgame/index/sxd/s94?from=0gsp_cps2345&source=cps&from_ly=cps2345
                )
        )
)
如果要访问stdClass的某个子元素:例$v->game_name

PHP中的NULL,”” ,0,”0″,1

$var             =    NULL      ""       0       "0"      1

strlen($var)     =    0         0        1        1       1
is_null($var)    =    TRUE    FALSE    FALSE    FALSE    FALSE
$var == ""       =    TRUE     TRUE     TRUE    FALSE    FALSE
!$var            =    TRUE     TRUE     TRUE     TRUE    FALSE
!is_null($var)   =    FALSE    TRUE     TRUE     TRUE     TRUE
$var != ""       =    FALSE    FALSE    FALSE    TRUE     TRUE
$var             =    FALSE    FALSE    FALSE    FALSE    TRUE

 

OO中self和$this的区别

What is the difference between  $this  and  self ?

Inside a class definition, $this refers to the current object, while  self  refers to the current class.

It is necessary to refer to a class element using  self ,
and refer to an object element using  $this .
Note also how an object variable must be preceded by a keyword in its definition.

The following example illustrates a few cases:

<?php
class Classy {

const       STAT = 'S' ; // no dollar sign for constants (they are always static)
static     $stat = 'Static' ;
public     $publ = 'Public' ;
private    $priv = 'Private' ;
protected  $prot = 'Protected' ;

function __construct( ){  }

public function showMe( ){
    print '<br> self::STAT: '  .  self::STAT ; // refer to a (static) constant like this
    print '<br> self::$stat: ' . self::$stat ; // static variable
    print '<br>$this->stat: '  . $this->stat ; // legal, but not what you might think: empty result
    print '<br>$this->publ: '  . $this->publ ; // refer to an object variable like this
    print '<br>' ;
}
}
$me = new Classy( ) ;
$me->showMe( ) ;

/* Produces this output:
self::STAT: S
self::$stat: Static
$this->stat:
$this->publ: Public
*/
?>

 

一个简单的抓链接spider

首先一个html表单form.html:

<form action="spider.php" method="post">
input your website you’d like to snatch:
<input type="text" name="website">
<input type="submit" value="Submit">
</form>

 

然后是spider.php:

<?php
if ($_POST["website"]) {
    $url = $_POST["website"];
} else {
    $url = ‘http://www.baidu.com’;
}
//echo $url;
$html = file_get_contents($url);
echo "Page : " . $url;
preg_match_all("/http://[^"s’]+/", $html, $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
    echo "<li>|–" . $val[0] . "<br>";
}
?>