【必须收藏的php实用代码片段,_PHP教程】教程文章相关的互联网学习教程文章

非常有用的9个PHP代码片段

本文我们就来分享一下我收集的一些超级有用的PHP代码片段。一起来看一看吧! 1.创建数据URI 数据URI在嵌入图像到HTML / CSS / JS中以节省HTTP请求时非常有用,并且可以减少网站的加载时间。下面的函数可以创建基于$file的数据URI。 function data_uri($file, $mime) {$contents=file_get_contents($file);$base64=base64_encode($contents);echo "data:$mime;base64,$base64"; } 2.合并JavaScript和CSS文件 另一个可以尽量减少HTTP...

php实用代码片段整理

本文整理归纳了php实用代码片段。分享给大家供大家参考,具体如下: 一 从网页中提取关键词 $meta = get_meta_tags(//www.gxlcms.com/); $keywords = $meta[keywords]; // Split keywords $keywords = explode(,, $keywords ); // Trim them $keywords = array_map( trim, $keywords ); // Remove empty values $keywords = array_filter( $keywords ); print_r( $keywords );二 查找页面上的所有链接 使用DOM,你可以在任意页面上...

6个超实用的PHP代码片段

一、黑名单过滤 function is_spam($text, $file, $split = :, $regex = false){ $handle = fopen($file, rb); $contents = fread($handle, filesize($file)); fclose($handle); $lines = explode("n", $contents); $arr = array(); foreach($lines as $line){ list($word, $count) = explode($split, $line); if($regex) $arr[$word] = $count; else $arr[preg_quote($word)] = $count; } preg_match_all("~".implode(|, ...

19个超实用的PHP代码片段

1) Whois query using PHP ——利用PHP获取Whois请求 利用这段代码,在特定的域名里可获得whois信息。把域名名称作为参数,并显示所有域名的相关信息。 代码如下:function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace(/^http:\/\//i, , $domain); $domain = preg_replace(/^www\./i, , $domain); $domain = explode(/, $domain); ...

10个典型实用的PHP代码片段【图】

本文将介绍10个经常会用到的PHP代码片段,包括黑名单过滤、随机颜色生成器、从网上下载文件、新疆阿克苏地区Alexa/Google Page Rank、强制下载文件、用Email显示用户的Gravator头像、用cURL获取RSS订阅数、截取图片、检查网站是否宕机。一、黑名单过滤 function is_spam($text, $file, $split = :, $regex = false){ $handle = fopen($file, rb); $contents = fread($handle, filesize($file)); fclose($handle); $lines = explode...

ide phpStorm常用代码片段设置【图】

1.打开设置(File -> Settings) 2.如图3 . 最后,在PHP文件中输入 ll 并按 TAB 即可打出代码块