1. 删除文件夹内容
Delete( (() === = ((),('.','..' ( () . '/' . ( (() === (
语法:
= "images/");
?>
2. 搜索和高亮字符串中的关键字
highlighter_text(, = ( " ",( = "#4285F4" = ("|()|Ui",".";\">$1",
语法:
= "I like chocolates and I like apples" = "apple" highlighter_text(,?>
3. 写入文件
= 'blog.csv' = (,'w' = " Hello " .= " World! " .= "\r\n"(,(?>
4. 根据 URL 下载图片
imagefromURL(, = curl_init(,CURLOPT_HEADER,0,CURLOPT_RETURNTRANSFER,1,CURLOPT_BINARYTRANSFER,1=curl_exec ( = ("",'w'(,(
语法:
= "http://koonk.com/images/logo.png" = "koonk.png",?>
5. 检测 URL 是否有效
isvalidURL( = 0 (filter_var(,FILTER_VALIDATE_URL) !== = 1
语法:
= "http://koonk.com" = checkvalidURL( ;
?>
6. 生成二维码
qr_code(, = "TXT", ='150',='L',='0' = ("URL" =--> "http://","TEL" => "TEL:","TXT"=>"","EMAIL" => "MAILTO:"(!(,("URL","TEL","TXT","EMAIL" = "TXT" (!('/^'.[].'/', = ("\\","",[]). = = (,CURLOPT_URL,'http://chart.apis.google.com/chart',CURLOPT_POST,,CURLOPT_POSTFIELDS,'chs='..'x'..'&cht=qr&chld='..'|'..'&chl='.,,CURLOPT_TIMEOUT,30 = curl_exec(
语法:
("Content-type: image/png" qr_code("http://koonk.com","URL"?>
7. 计算两个地图坐标之间的距离
getDistanceBetweenPointsNew(,,, = - = ((()) * (())) + ((()) * (()) * (( = ( = ( = * 60 * 1.1515 = * 5280 = / 3 = * 1.609344 = * 1000 ('miles','feet','yards','kilometers','meters'
语法:
= ('lat' => 40.770623,'long' => -73.964367 = ('lat' => 40.758224,'long' => -73.917404 = getDistanceBetweenPointsNew(['lat'],['long'],['lat'],['long' ( => .': '.(,4).'
'?>
'?>
8. 获取一个特定话题标签的所有 Tweets
getTweets( = 'http://search.twitter.com/search.atom?q='.( "
Connecting to ...
" = curl_init(, = curl_exec (Response:"; //echo "".htmlspecialchars($xml).""; = 0 = SimpleXMLElement( (->entry = (-> = (->author-> = (-> = -> "
Tweet from "..": ".." Posted ".('n/j/y g:i a',)."
"9. 添加 th,st,nd 或者 rd 作为数字的后缀
ordinal( = () % 10 = ((() %100 < 21 && () %100 > 4) ? 'th'
: (( < 4) ? ( < 3) ? ( < 2) ? ( < 1? 'th' : 'st' : 'nd' : 'rd' : 'th' .
语法:
= 10 ordinal();
?>
10. 限制文件下载的速度
= 'test-file.zip'
= 'your-download-name.zip'<span style="color: #008000">//<span style="color: #008000"> set the download rate limit (=> 20,5 kb/s)
<span style="color: #800080">$download_rate = 20.5<span style="color: #000000">;
<span style="color: #0000ff">if(<span style="color: #008080">file_exists(<span style="color: #800080">$local_file) && <span style="color: #008080">is_file(<span style="color: #800080">$local_file<span style="color: #000000">)) {
<span style="color: #008000">//<span style="color: #008000"> send headers
<span style="color: #008080">header('Cache-control: private'<span style="color: #000000">);
<span style="color: #008080">header('Content-Type: application/octet-stream'<span style="color: #000000">);
<span style="color: #008080">header('Content-Length: '.<span style="color: #008080">filesize(<span style="color: #800080">$local_file<span style="color: #000000">));
<span style="color: #008080">header('Content-Disposition: filename='.<span style="color: #800080">$download_file<span style="color: #000000">);
<span style="color: #800080">$download_rate = 20.5<span style="color: #000000">;
<span style="color: #0000ff">if(<span style="color: #008080">file_exists(<span style="color: #800080">$local_file) && <span style="color: #008080">is_file(<span style="color: #800080">$local_file<span style="color: #000000">)) {
<span style="color: #008000">//<span style="color: #008000"> send headers
<span style="color: #008080">header('Cache-control: private'<span style="color: #000000">);
<span style="color: #008080">header('Content-Type: application/octet-stream'<span style="color: #000000">);
<span style="color: #008080">header('Content-Length: '.<span style="color: #008080">filesize(<span style="color: #800080">$local_file<span style="color: #000000">));
<span style="color: #008080">header('Content-Disposition: filename='.<span style="color: #800080">$download_file<span style="color: #000000">);
</span><span style="color: #008000">//</span><span style="color: #008000"> flush content</span>
<span style="color: #008080">flush</span><span style="color: #000000">();
</span><span style="color: #008000">//</span><span style="color: #008000"> open file stream</span>
<span style="color: #800080">$file</span> = <span style="color: #008080">fopen</span>(<span style="color: #800080">$local_file</span>,"r"<span style="color: #000000">);
</span><span style="color: #0000ff">while</span>(!<span style="color: #008080">feof</span>(<span style="color: #800080">$file</span><span style="color: #000000">)) {
</span><span style="color: #008000">//</span><span style="color: #008000"> send the current file part to the browser</span>
<span style="color: #0000ff">print</span> <span style="color: #008080">fread</span>(<span style="color: #800080">$file</span>,<span style="color: #008080">round</span>(<span style="color: #800080">$download_rate</span> * 1024<span style="color: #000000">));
</span><span style="color: #008000">//</span><span style="color: #008000"> flush the content to the browser</span>
<span style="color: #008080">flush</span><span style="color: #000000">();
</span><span style="color: #008000">//</span><span style="color: #008000"> sleep one second</span>
<span style="color: #008080">sleep</span>(1<span style="color: #000000">);
}
</span><span style="color: #008000">//</span><span style="color: #008000"> close file stream</span>
<span style="color: #008080">fclose</span>(<span style="color: #800080">$file</span><span style="color: #000000">);}
<span style="color: #0000ff">else<span style="color: #000000"> {
<span style="color: #0000ff">die('Error: The file '.<span style="color: #800080">$local_file.' does not exist!'<span style="color: #000000">);
}
?>
11. 把文本转换成图片
("Content-type: image/png" = ['text' = imagecreatefrompng("images/button.png" = imagecolorallocate(,255,255 = (imagesx() - 7.5 * ()) / 2 = 9 = 1,fontSize,,,,?>
12. 获取远程文件的大小
remote_filesize(, = "", = "" = curl_init(,1,CURLOPT_NOBODY,1(!() && !( = ('Authorization: Basic ' . (":",CURLOPT_HTTPHEADER, = curl_exec( = = '/Content-Length:\s([0-9].+?)\s/' = (,, ([1]) ? [1] : "unknown"
语法:
= "http://koonk.com/images/logo.png" = remote_filesize( ?>
13. 使用 imagebrick 进行 pdf 到图像的转换
= './pdf/demo.pdf' = './jpg/demo.jpg';
('convert "'..'" -colorspace RGB -resize 800 "'..'"',,( == 0) {
"Conversion OK" "Conversion failed.
".?>
".?>
14. 使用 tinyurl 生成短网址
get_tiny_url( = = 5,'http://tinyurl.com/api-create.php?url='.,1,CURLOPT_CONNECTTIMEOUT, = curl_exec(
语法:
= "http://blog.koonk.com/2015/07/Hello-World" = get_tiny_url( ?>
15. youtube 下载链接生成器
str_between(,, = " ".; = (,); ( == 0) ""; += (); = (,,) - ; (,, = ['youtube' = ( = str_between(,"&video_id=","&" = str_between(,"&t=","&" = "http://www.youtube.com/get_video?video_id=&t=" = "http://www.youtube.com/get_video?video_id=&t=&fmt=6" = "http://www.youtube.com/get_video?video_id=&t=&fmt=18" = "http://www.youtube.com/get_video?video_id=&t=&fmt=17" "\t\tDownload (right-click > save as):\n\t\t" "\">FLV\n\t\t" "\">HQ FLV (if available)\n\t\t" "\">MP4\n\t\t" "\">3GP
\n"
\n"
16. Facebook 样式的时间戳
Facebook (x mins age,y hours ago etc)
nicetime((( "No date provided"
</span><span style="color: #800080">$periods</span> = <span style="color: #0000ff">array</span>("second","minute","hour","day","week","month","year","decade"<span style="color: #000000">);
</span><span style="color: #800080">$lengths</span> = <span style="color: #0000ff">array</span>("60","60","24","7","4.35","12","10"<span style="color: #000000">);
</span><span style="color: #800080">$now</span> = <span style="color: #008080">time</span><span style="color: #000000">();
</span><span style="color: #800080">$unix_date</span> = <span style="color: #008080">strtotime</span>(<span style="color: #800080">$date</span><span style="color: #000000">);
</span><span style="color: #008000">//</span><span style="color: #008000"> check validity of date</span>
<span style="color: #0000ff">if</span>(<span style="color: #0000ff">empty</span>(<span style="color: #800080">$unix_date</span><span style="color: #000000">)) {
</span><span style="color: #0000ff">return</span> "Bad date"<span style="color: #000000">;
}
</span><span style="color: #008000">//</span><span style="color: #008000"> is it future date or past date</span>
<span style="color: #0000ff">if</span>(<span style="color: #800080">$now</span> > <span style="color: #800080">$unix_date</span><span style="color: #000000">) {
</span><span style="color: #800080">$difference</span> = <span style="color: #800080">$now</span> - <span style="color: #800080">$unix_date</span><span style="color: #000000">;
</span><span style="color: #800080">$tense</span> = "ago"<span style="color: #000000">;
} </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
</span><span style="color: #800080">$difference</span> = <span style="color: #800080">$unix_date</span> - <span style="color: #800080">$now</span><span style="color: #000000">;
</span><span style="color: #800080">$tense</span> = "from now"<span style="color: #000000">;
}
</span><span style="color: #0000ff">for</span>(<span style="color: #800080">$j</span> = 0; <span style="color: #800080">$difference</span> >= <span style="color: #800080">$lengths</span>[<span style="color: #800080">$j</span>] && <span style="color: #800080">$j</span> < <span style="color: #008080">count</span>(<span style="color: #800080">$lengths</span>)-1; <span style="color: #800080">$j</span>++<span style="color: #000000">) {
</span><span style="color: #800080">$difference</span> /= <span style="color: #800080">$lengths</span>[<span style="color: #800080">$j</span><span style="color: #000000">];
}
</span><span style="color: #800080">$difference</span> = <span style="color: #008080">round</span>(<span style="color: #800080">$difference</span><span style="color: #000000">);
</span><span style="color: #0000ff">if</span>(<span style="color: #800080">$difference</span> != 1<span style="color: #000000">) {
</span><span style="color: #800080">$periods</span>[<span style="color: #800080">$j</span>].= "s"<span style="color: #000000">;
}
</span><span style="color: #0000ff">return</span> "<span style="color: #800080">$difference</span> <span style="color: #800080">$periods</span>[<span style="color: #800080">$j</span>] {<span style="color: #800080">$tense</span>}"<span style="color: #000000">;
}
语法:
= "2015-07-05 03:45" = nicetime();
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。