php 函数摘录(mainly from wordpress and php manual)--持续更新
2012-04-03 19:08
435 查看
wordpress functions:
1.深度替换(拿替换后的结果再次替换)/** * Perform a deep string replace operation to ensure the values in $search are no longer present * * Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values * e.g. $subject = '%0%0%0DDD', $search ='%0D', $result ='' rather than the '%0%0DD' that * str_replace would return * * @since 2.8.1 * @access private * * @param string|array $search * @param string $subject * @return string The processed string */ function _deep_replace( $search, $subject ) { $found = true; $subject = (string) $subject; while ( $found ) { $found = false; foreach ( (array) $search as $val ) { while ( strpos( $subject, $val ) !== false ) { $found = true; $subject = str_replace( $val, '', $subject ); } } } return $subject; }
2.vars.php
检测浏览器
// Simple browser detection $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = false; if ( isset($_SERVER['HTTP_USER_AGENT']) ) { if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) { $is_lynx = true; } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) { if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) { if ( $is_chrome = apply_filters( 'use_google_chrome_frame', is_admin() ) ) header( 'X-UA-Compatible: chrome=1' ); $is_winIE = ! $is_chrome; } else { $is_chrome = true; } } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) { $is_safari = true; } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) { $is_gecko = true; } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) { $is_winIE = true; } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) { $is_macIE = true; } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) { $is_opera = true; } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) { $is_NS4 = true; } } if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false ) $is_iphone = true; $is_IE = ( $is_macIE || $is_winIE );
3.检测服务器
// Server detection /** * Whether the server software is Apache or something else * @global bool $is_apache */ $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false); /** * Whether the server software is IIS or something else * @global bool $is_IIS */ $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false); /** * Whether the server software is IIS 7.X * @global bool $is_iis7 */ $is_iis7 = $is_IIS && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
php manual functions:
1.深度去除反斜线(json string)<?php function stripslashes_deep(&$value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } ?>
2.转义字符串,用于sql
<?php function conditional_escape ($str) { /* Automatic escaping is highly deprecated, but many sites do it anyway to protect themselves from stupid customers. */ if (get_magic_quotes_gpc()) { /* Apache automatically escaped the string already. */ return $str; } /* Replace the following line with whatever function you prefer to call to escape a string. */ return mysqli_real_escape_string ($link, $str); } ?>
相关文章推荐
- PHP - Manual手册 - XXXIII. Error Handling and Logging Functions错误处理和日志函数 - 概述
- PHP项目中可能用到的函数(持续更新)
- PHP - Manual手册 - Function Reference函数参考 - Variable and Type Related Extensions变量和类型相关扩展 - Arrays数组 - Array Functions数组函数 - ksort
- php常用函数(持续更新)
- PHP常用的一些公共函数(持续更新)
- php 常用的好函数(持续更新)
- PHP 常用 函数总结 持续更新中...
- PHP - Manual手册 - Function Reference函数参考 - Variable and Type Related Extensions变量和类型相关扩展 - Variable handling变量操作 - Variable handl
- MySQL - 翻译 - 5.1Reference Manual参考手册 - 11.6. Date and Time Functions日期和时间函数 - FROM_UNIXTIME将UNIX时间戳格式化为日期
- PHP常用函数总结(180多个)[持续更新中...]
- php源码函数汇总(持续更新)
- 【WordPress】WordPress加速汇总(持续更新)
- Pattern Recognition and Machine Learning 读书总结(持续更新中)
- PHP关于数组的操作(持续更新)
- Beginning PHP and PostgreSQL 8: From Novice to Professional
- MySQL 5.7 Reference Manual Chapter 13 Functions and Operators 参考手册第十三章函数与操作符内容总结
- 【转】How to build and install PHP 5.6.9 from source on Ubuntu 14.04 VPS
- Beginning PHP and MySQL 5: From Novice to Professional, Second Edition
- mssql 中的函数[持续更新]
- PHP Manual 笔记(更新中)