- 浏览: 196938 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
guji528:
使用Python通过正则表达式替换很方便:
sprin ...
Python正则表达式指南 -
guji528:
很实用,先keep再看
Python正则表达式指南 -
yushine:
1,2,3,5 已经做了剩下的本来也正准备做。
2012, 每一个软件工程师必须做的11件事 -
mynetstudy:
用导出不就可以了吗
递归删除SVN工作目录下的.svn目录
1. 发送短信
调用 TextMagic API。
// Include the TextMagic PHP lib
require('textmagic-sms-api-php/TextMagicAPI.php');
// Set the username and password information
$username = 'myusername';
$password = 'mypassword';
// Create a new instance of TM
$router = new TextMagicAPI(array(
'username' => $username,
'password' => $password
));
// Send a text message to '999-123-4567'
$result = $router->send('Wake up!', array(9991234567), true);
// result: Result is: Array ( [messages] => Array ( [19896128] => 9991234567 ) [sent_text] => Wake up! [parts_count] => 1 )
2. 根据IP查找地址
function detect_city($ip) {
$default = 'UNKNOWN';
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')
$ip = '8.8.8.8';
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip);
$ch = curl_init();
$curl_opt = array(
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => $curlopt_useragent,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 1,
CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
);
curl_setopt_array($ch, $curl_opt);
$content = curl_exec($ch);
if (!is_null($curl_info)) {
$curl_info = curl_getinfo($ch);
}
curl_close($ch);
if ( preg_match('{<li>City : ([^<]*)</li>}i', $content, $regs) ) {
$city = $regs[1];
}
if ( preg_match('{<li>State/Province : ([^<]*)</li>}i', $content, $regs) ) {
$state = $regs[1];
}
if( $city!='' && $state!='' ){
$location = $city . ', ' . $state;
return$location;
}else{
return$default;
}
}
3. 显示网页的源代码
<?php // display source code
$lines = file('http://google.com/');
foreach ($lines as $line_num => $line) {
// loop thru each line and prepend line numbers
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
4. 检查服务器是否使用HTTPS
if ($_SERVER['HTTPS'] != "on") {
echo "This is not HTTPS";
}else{
echo "This is HTTPS";
}
5. 显示Faceboo**丝数量
function fb_fan_count($facebook_name){
// Example: https://graph.facebook.com/digimantra
$data = json_decode(file_get_contents("https://graph.facebook.com/".$facebook_name));
echo $data->likes;
}
6. 检测图片的主要颜色
$i = imagecreatefromjpeg("image.jpg");
for ($x=0;$x<imagesx($i);$x++) {
for ($y=0;$y<imagesy($i);$y++) {
$rgb = imagecolorat($i,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> & 0xFF;
$b = $rgb & 0xFF;
$rTotal += $r;
$gTotal += $g;
$bTotal += $b;
$total++;
}
}
$rAverage = round($rTotal/$total);
$gAverage = round($gTotal/$total);
$bAverage = round($bTotal/$total);
7. 获取内存使用信息
echo"Initial: ".memory_get_usage()." bytes \n";
/* prints
Initial: 361400 bytes
*/
// http://www.baoluowanxiang.com/
// let's use up some memory
for ($i = 0; $i < 100000; $i++) {
$array []= md5($i);
}
// let's remove half of the array
for ($i = 0; $i < 100000; $i++) {
unset($array[$i]);
}
echo"Final: ".memory_get_usage()." bytes \n";
/* prints
Final: 885912 bytes
*/
echo"Peak: ".memory_get_peak_usage()." bytes \n";
/* prints
Peak: 13687072 bytes
*/
8. 使用 gzcompress() 压缩数据
$string =
"Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nunc ut elit id mi ultricies
adipiscing. Nulla facilisi. Praesent pulvinar,
sapien vel feugiat vestibulum, nulla dui pretium orci,
non ultricies elit lacus quis ante. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Aliquam
pretium ullamcorper urna quis iaculis. Etiam ac massa
sed turpis tempor luctus. Curabitur sed nibh eu elit
mollis congue. Praesent ipsum diam, consectetur vitae
ornare a, aliquam a nunc. In id magna pellentesque
tellus posuere adipiscing. Sed non mi metus, at lacinia
augue. Sed magna nisi, ornare in mollis in, mollis
sed nunc. Etiam at justo in leo congue mollis.
Nullam in neque eget metus hendrerit scelerisque
eu non enim. Ut malesuada lacus eu nulla bibendum
id euismod urna sodales. ";
$compressed = gzcompress($string);
echo "Original size: ". strlen($string)."\n";
/* prints
Original size: 800
*/
echo "Compressed size: ". strlen($compressed)."\n";
/* prints
Compressed size: 418
*/
// getting it back
$original = gzuncompress($compressed);
9. 使用PHP做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);
$domain = trim($domain[0]);
// split the TLD from domain name
$_domain = explode('.', $domain);
$lst = count($_domain)-1;
$ext = $_domain[$lst];
// You find resources and lists
// like these on wikipedia:
//
// http://de.wikipedia.org/wiki/Whois
//
$servers = array(
"biz" => "whois.neulevel.biz",
"com" => "whois.internic.net",
"us" => "whois.nic.us",
"coop" => "whois.nic.coop",
"info" => "whois.nic.info",
"name" => "whois.nic.name",
"net" => "whois.internic.net",
"gov" => "whois.nic.gov",
"edu" => "whois.internic.net",
"mil" => "rs.internic.net",
"int" => "whois.iana.org",
"ac" => "whois.nic.ac",
"ae" => "whois.uaenic.ae",
"at" => "whois.ripe.net",
"au" => "whois.aunic.net",
"be" => "whois.dns.be",
"bg" => "whois.ripe.net",
"br" => "whois.registro.br",
"bz" => "whois.belizenic.bz",
"ca" => "whois.cira.ca",
"cc" => "whois.nic.cc",
"ch" => "whois.nic.ch",
"cl" => "whois.nic.cl",
"cn" => "whois.cnnic.net.cn",
"cz" => "whois.nic.cz",
"de" => "whois.nic.de",
"fr" => "whois.nic.fr",
"hu" => "whois.nic.hu",
"ie" => "whois.domainregistry.ie",
"il" => "whois.isoc.org.il",
"in" => "whois.ncst.ernet.in",
"ir" => "whois.nic.ir",
"mc" => "whois.ripe.net",
"to" => "whois.tonic.to",
"tv" => "whois.tv",
"ru" => "whois.ripn.net",
"org" => "whois.pir.org",
"aero" => "whois.information.aero",
"nl" => "whois.domain-registry.nl"
);
if (!isset($servers[$ext])){
die('Error: No matching nic server found!');
}
$nic_server = $servers[$ext];
$output = '';
// connect to whois server:
if ($conn = fsockopen ($nic_server, 43)) {
fputs($conn, $domain."\r\n");
while(!feof($conn)) {
$output .= fgets($conn,128);
}
fclose($conn);
}
else { die('Error: Could not connect to ' . $nic_server . '!'); }
return $output;
}
10. 通过Email发送PHP错误
<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";
$email .= "<pre>" . print_r($vars, 1) . "</pre>";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Email the error to someone...
error_log($email, 1, 'you@youremail.com', $headers);
// Make sure that you decide how to respond to errors (on the user's side)
// Either echo an error message, or kill the entire project. Up to you...
// The code below ensures that we only "die" if the error was more than
// just a NOTICE.
if ( ($number !== E_NOTICE) && ($number < 2048) ) {
die("There was an error. Please try again later.");
}
}
// We should use our custom function to handle errors.
set_error_handler('nettuts_error_handler');
// Trigger an error... (var doesn't exist)
echo$somevarthatdoesnotexist;
发表评论
-
Magento模板及布局文件中引用Static Block的方法
2013-03-21 10:25 1256Static Block是Magento提供的非常实用的一种 ... -
PHP ORM框架与简单代码实现
2013-02-18 12:37 1391对象关系映射(Object Relational Mappi ... -
php.ini安全配置详细解释
2013-01-24 11:28 1896PHP本身再老版本有一些问题,比如在 php4.3.10和p ... -
关于PHP学习
2012-11-02 21:54 7891.首先看了PHP的源码API ... -
Zend Framework的DB处理-表关联(转载)
2012-04-24 10:35 1124介绍: 在RDBMS中,表之间有着各种 ... -
浅谈Zend Framework, CodeIgniter与Kohana
2012-04-13 17:11 1178抛砖引玉,这三份框架 我都花了一定的时间精力去了解,根据 ... -
浅谈Zend Framework, CodeIgniter与Kohana
2012-04-13 17:10 14<div id="article_conten ... -
22个开源的PHP框架
2012-02-06 12:40 943http://coolshell.cn/articles/10 ... -
Drupal 主页定制:定制个性的drupal 主页<front>
2011-11-24 23:48 1030默认主题就是列表格式,像blog一样,一般做企业展示性的网站, ... -
drupal6.x中创建新的主题模版和区域(Regions)
2011-11-24 23:27 15542011-01-02 18:29 ... -
9大最有潜力PHP开源项目:PHP FOR Android开发居首
2011-11-10 11:21 1500PHP的开源世界可谓相当 ... -
Comparing PHP Frameworks ( Symfony, CakePHP, YII and CodeIgniter)
2011-06-30 18:13 1523转自 http://karim-ouda.blogspot.c ... -
A Good PHPer
2011-01-18 16:35 7291.首先看了PHP的源码API函数,对于许多口水仗的争论一笑而 ... -
PHP实现html标签补全
2011-01-18 15:37 1144PHP实现html标签补全 作者:朦朧中的罪惡 | ... -
Comparison of web application frameworks
2011-01-18 15:29 990From Wikipedia, the free encycl ... -
搭建Eclipse PDT开发CakePHP的环境
2011-01-14 14:20 2638搭建Eclipse PDT开发CakePHP ... -
Developing custom PHP extensions PECL Tutorials 从源程序编译 DLL
2011-01-04 17:34 1763想了很久怎么给这篇文 ... -
国外主流PHP框架比较-CodeIgniter、CakePHP、ZendFramework、Symfony
2010-12-01 13:16 1211最近简单的使用了目前在国内用的比较多的几个主流国外PHP框架( ... -
面向 PHP 5.3 友好的 PHP 开发
2010-10-12 13:57 1177最近 Debian 的 testing 版 ... -
php5.3不支持eregi()函数了
2010-10-12 13:52 8634写正则的时候可能会碰到用ereg()时出现错误,如:Depre ...
相关推荐
isolated-vm
Visual Studio 2013 Shell (Isolated)
led驱动40.5 W, High Power Factor (-0.95), -5% IOUT Tolerance, Non-Isolated Buck LED Driver Using LinkSwitchTM-PH LNK419EG
induction generator in isolated grid
1、sqlserver 2012 因为卸载vs2010后无法正常使用,需要重新安装该插件
根据每个传感器的剩余能量和每个簇中所有传感器的区域平均能量确定权重。不适当地设计分布式集群算法会导致节点与CHs隔离。这些孤立的节点通过消耗过多的能量与外界进行通信。为了延长网络的生存期,利用区域平均...
WP7 Isolated Storage Explorer
艾络格电子工业 RS232 & RS485/422 Isolated 转换器zip,艾络格电子工业 RS232 & RS485/422 隔离转换器
Troubleshooting C C++ Isolated Applications and Side-by-side Assemblies. 发现并解决C C++独立应用程序和并行程序集的问题(无法运行VS2008开发的MFCC++程序的参考)
tf-vrouter
isolated-vm-访问Node.js中的多个隔离 isolated-vm是nodejs的库,可让您访问v8的Isolate接口。 这使您可以创建彼此完全隔离的JavaScript环境。 如果您需要以安全的方式运行一些不受信任的代码,则可能会发现此模块...
Virginia Tech- ACTIVE-CLAMP FLYBACK AS AN ISOLATED PFC FRONT-END CONVERTER
window phone 8 Backup Isolated Storage To SkyDrive
可以实现简单孤立词的识别和训练,内有1到9的录音,可以自己训练。
Enterocin from Enterococcus faecium isolated from mangrove environment
Measurement of Mitochondrial Respiration in Isolated Protoplasts_ Cytochrome and Alternative Pathways
Alkaline protease production from newly isolated plant growth promoting rhizobacteria
隔离 vm-cli CLI 使用虚拟机 nodejs 库在隔离环境中运行 Javascript 文件。... isolated-vm 是一个用于 nodejs 的库,它可以让你访问 v8 的 Isolate 接口。 这个 cli 只是使用这个 nodejs 库在安全环境中运行
POINT I/O RTD and Isolated Thermocouplepdf,POINT I/O RTD and Isolated Thermocouple
An Improved Non-isolated LED Converter with Power Factor Correction and Average Current Mode Control