---
title: "php5新函数"
author: "myfreespace"
date: "2011-11-18T14:29:37Z"
tags: []
categories: ["Web前端"]
slug: "php5"
draft: false
lastmod: "2011-11-18T14:29:37Z"
id: 1265666
url: "https://myfreespace.iteye.com/blog/1265666"
---

php5发布有一段时间了，不过对于php的函数还停留在php4甚至更早，这样就重复这造轮子了，看了看手册和网上的资料整理一部分php5的函数。

1.**filter\_var(str,int filter) 这个函数是用来验证邮箱地址 url等地址,**可以用php自己默认定义的，也可以自己定义filter来匹配

```
var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));
var_dump(filter_var('example.com', FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED));
上面将输出
string(15) "bob@example.com"
bool(false)

```

 2.**debug\_print\_backtrace打印程序的调用堆栈信息,比以前的echo print好用，比xdebug简单**

```
<?php
// include.php file

function a() {
    b();
}

function b() {
    c();
}

function c(){
    debug_print_backtrace();
}

a();

?> 
//上面将输出

#0  eval() called at [/tmp/include.php:5]
#1  a() called at [/tmp/include.php:17]
#2  include(/tmp/include.php) called at [/tmp/test.php:3]

#0  c() called at [/tmp/include.php:10]
#1  b() called at [/tmp/include.php:6]
#2  a() called at [/tmp/include.php:17]
#3  include(/tmp/include.php) called at [/tmp/test.php:3]
```