ITPub博客

首页 > IT职业 > IT生活 > PHP函数

PHP函数

IT生活 作者:sunrh 时间:2021-09-09 09:19:13 0 删除 编辑

1.

PHP stristr() 函数

PHP String 函数

定义和用法

stristr() 函数查找字符串在另一个字符串中第一次出现的位置。

如果成功,则返回字符串的其余部分(从匹配点)。如果没有找到该字符串,则返回 false。

语法

stristr(string,search)

2.rawurldecode()

rawurldecode — 对已编码的 URL 字符串进行解码

rawurldecode() 不会把加号('+')解码为空格,而    urldecode() 可以。


3.set_time_limit(0);

括号里边的数字是执行时间,如果为零说明永久执行直到程序结束,如果为大于零的数字,则不管程序是否执行完成,到了设定的秒数,程序结束。

4.get_magic_quotes_gpc()

magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post、get、cookie过来的数据增加转义字符“”

在PHP6中***了magic_quotes_gpc这个选项  $c=(!get_magic_quotes_gpc())?addslashes($c):$c;

5.str_pad()把字符串填充为指定的长度

str_pad(string,length,pad_string,pad_type)str_pad($str,20,".");

6.

call_user_func_array

(PHP 4 >= 4.0.4, PHP 5)

call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数

function foobar($arg, $arg2) {
    echo __FUNCTION__, " got $arg and $arg2n";
}
class foo {
    function bar($arg, $arg2) {
        echo __METHOD__, " got $arg and $arg2n";
    }
}


// Call the foobar() function with 2 arguments
call_user_func_array("foobar", array("one", "two"));

// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four"));
?>

7.

http_build_query — 生成 URL-encode 之后的请求字符串

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "n";
echo http_build_query($data, '', '&');

?>

以上例程会输出:

foo=bar&baz=boom&cow=milk&php=hypertext+processorfoo=bar&baz=boom&cow=milk&php=hypertext+processor

8.

addChild() 函数

PHP SimpleXML 函数

addChild() 函数向指定的 XML 节点添加一个子节点。

该函数返回一个 SimpleXMLElement 对象,这个对象表示添加到 XML 节点的子元素。

语法

class SimpleXMLElement{string addChild(name,value,ns)}
参数 描述
name 必需。规定子元素的名称。
value 必需。规定子元素的值。
ns 可选。规定子元素的命名空间。

例子

XML 文件:

GeorgeJohnReminderDon't forget the meeting!

PHP 代码:

body[0]->addChild("date", "2008-08-08");foreach ($xml->body->children() as $child)  {  echo "Child node: " . $child;  }?>

输出:

Child node: 2008-08-08

9.filter_input()

filter_input() 函数从脚本外部获取输入,并进行过滤。

本函数用于对来自非安全来源的变量进行验证,比如用户的输入。

本函数可从各种来源获取输入:

  • INPUT_GET

  • INPUT_POST

  • INPUT_COOKIE

  • INPUT_ENV

  • INPUT_SERVER

  • INPUT_SESSION (Not yet implemented)

  • INPUT_REQUEST (Not yet implemented)

如果成功,则返回被过滤的数据,如果失败,则返回 false,如果 variable 参数未设置,则返回 NULL。

语法

filter_input(input_type, variable, filter, options)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2505/viewspace-2802137/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    91
  • 访问量
    715