1 MySQL中把null值转换为0的函数?
| 1 | select ifnull(null,0); |
2 PHP 过滤Win系统文件名中的非法字符
| 1 | <?php |
| 2 | $this->media_planning_name = str_replace(array(‘/‘,‘\\‘,‘:‘,‘*‘,‘?‘,‘"‘,‘<‘,‘>‘,‘|‘),‘_‘, trim($media_planning_name)); |
| 3 | ?> |
3 遍历两个日期间的日期
比如,要遍历出2009-2-10,到2009-3-30 之间的日期
| 1 | <?php for($i = $media_planning_start_date; $i<= $media_planning_end_date; $i = date(‘Y-m-d‘,strtotime("+1 days ".$i))):?> |
| 2 | <?php echo $i; ?> |
| 3 | <?php endfor;?> |
4 在Eclipse Xdebug调试中,查看$this->account_id 的值
$this
–varHolder
—-parameters
查看所有参数:
$this
–requestParameters
5 文件下载:
| 1 | <? |
| 2 | $report_file = ‘http://‘.$this->getRequest()->getHost().‘/‘.sfConfig::get(‘sf_reports_dir‘).‘/‘.$report->getReportPath(); |
| 3 | $FileParts = pathinfo($report_file); |
| 4 | $FileName = $FileParts['basename']; |
| 5 | //文件扩展名 |
| 6 | if (isset($FileParts['extension'])) |
| 7 | { |
| 8 | $Ream = $FileParts['extension']; |
| 9 | header( "Content-Type: application/x-".$Ream); |
| 10 | header( "Content-Disposition: attachment; filename=".$FileName); |
| 11 | @readfile($report_file); |
| 12 | exit; |
| 13 | } |
| 14 | header( "Content-Type: application/x-unknown"); |
| 15 | header( "Content-Disposition: attachment; filename=".$FileName); |
| 16 | @readfile($report_file); |
| 17 | exit; |
| 18 | ?> |
6 数组转换成字符串
| 1 | <?php |
| 2 | //涉及函数:implode() |
| 3 | $array = array(‘last‘,‘email‘,‘phone‘); |
| 4 | $str_array = implode(‘,‘, $array) |
| 5 | // last,email,phone |
| 6 | ?> |
另外一种实现方法,Join函数
| 1 | <?php |
| 2 | // Function join() |
| 3 | $array = array(‘lastname‘, ‘email‘, ‘phone‘); |
| 4 | $comma_separated = join(",", $array); |
| 5 | echo $comma_separated; // lastname,email,phone |
| 6 | ?> |