PHP FILTER_CALLBACK 过滤器

PHP 教程 · 2019-01-25 19:28:14

定义和用法

FILTER_CALLBACK 过滤器调用用户自定义函数来过滤数据。

该过滤器为我们提供了对数据过滤的完全控制。

指定的函数必须存入名为 "options" 的关联数组中。请参见下面的实例。

  • Name: "callback"
  • ID-number: 1024

提示和注释

提示:您可以创建自己的函数,或者使用已有的 PHP 函数。

实例 1

使用用户定义的函数:


<?php
function convertSpace($string)
  {
  return str_replace(" ", "_", $string);
  }
$string = "Peter is a great guy!";
echo filter_var($string, FILTER_CALLBACK,
array("options"=>"convertSpace"));
?>

代码的输出如下所示:


Peter_is_a_great_guy!


实例 2

使用现有的 PHP 函数:


<?php
$string="Peter is a great guy!";
echo filter_var($string, FILTER_CALLBACK,
array("options"=>"strtoupper"));
?>

代码的输出如下所示:


PETER IS A GREAT GUY!


点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Graph Algorithms

Graph Algorithms

Shimon Even / Cambridge University Press / 2011-9-19 / USD 32.99

Shimon Even's Graph Algorithms, published in 1979, was a seminal introductory book on algorithms read by everyone engaged in the field. This thoroughly revised second edition, with a foreword by Richa......一起来看看 《Graph Algorithms》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具