- 浏览: 201391 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 1294Static Block是Magento提供的非常实用的一种 ... -
PHP ORM框架与简单代码实现
2013-02-18 12:37 1446对象关系映射(Object Relational Mappi ... -
php.ini安全配置详细解释
2013-01-24 11:28 1944PHP本身再老版本有一些问题,比如在 php4.3.10和p ... -
关于PHP学习
2012-11-02 21:54 8271.首先看了PHP的源码API ... -
Zend Framework的DB处理-表关联(转载)
2012-04-24 10:35 1202介绍: 在RDBMS中,表之间有着各种 ... -
浅谈Zend Framework, CodeIgniter与Kohana
2012-04-13 17:11 1264抛砖引玉,这三份框架 我都花了一定的时间精力去了解,根据 ... -
浅谈Zend Framework, CodeIgniter与Kohana
2012-04-13 17:10 14<div id="article_conten ... -
22个开源的PHP框架
2012-02-06 12:40 974http://coolshell.cn/articles/10 ... -
Drupal 主页定制:定制个性的drupal 主页<front>
2011-11-24 23:48 1074默认主题就是列表格式,像blog一样,一般做企业展示性的网站, ... -
drupal6.x中创建新的主题模版和区域(Regions)
2011-11-24 23:27 15892011-01-02 18:29 ... -
9大最有潜力PHP开源项目:PHP FOR Android开发居首
2011-11-10 11:21 1544PHP的开源世界可谓相当 ... -
Comparing PHP Frameworks ( Symfony, CakePHP, YII and CodeIgniter)
2011-06-30 18:13 1558转自 http://karim-ouda.blogspot.c ... -
A Good PHPer
2011-01-18 16:35 7671.首先看了PHP的源码API函数,对于许多口水仗的争论一笑而 ... -
PHP实现html标签补全
2011-01-18 15:37 1189PHP实现html标签补全 作者:朦朧中的罪惡 | ... -
Comparison of web application frameworks
2011-01-18 15:29 1017From Wikipedia, the free encycl ... -
搭建Eclipse PDT开发CakePHP的环境
2011-01-14 14:20 2681搭建Eclipse PDT开发CakePHP ... -
Developing custom PHP extensions PECL Tutorials 从源程序编译 DLL
2011-01-04 17:34 1806想了很久怎么给这篇文 ... -
国外主流PHP框架比较-CodeIgniter、CakePHP、ZendFramework、Symfony
2010-12-01 13:16 1297最近简单的使用了目前在国内用的比较多的几个主流国外PHP框架( ... -
面向 PHP 5.3 友好的 PHP 开发
2010-10-12 13:57 1216最近 Debian 的 testing 版 ... -
php5.3不支持eregi()函数了
2010-10-12 13:52 8666写正则的时候可能会碰到用ereg()时出现错误,如:Depre ...
相关推荐
7. **智能代码编辑**:即使是 Isolated Shell,也支持智能代码编辑功能,如语法高亮、自动完成、代码重构等,这些特性对于提高开发效率有着不可替代的作用。 8. **多语言支持**:通过安装相应的组件和服务,...
"isolated-vm"是一个与虚拟化技术相关的概念,它通常指的是在计算机系统中创建一个独立、隔离的虚拟环境,这种环境称为隔离的虚拟机。在这个环境中,操作系统和其他应用程序可以运行,而不会影响主机系统或其他...
WP7 Isolated Storage Explorer是一款专为Windows Phone 7(WP7)平台设计的工具,用于帮助开发者和用户方便地查看、管理和操作手机上的Isolated Storage。Isolated Storage是.NET框架提供的一种安全、隔离的存储...
【Isolated vRouter Setup and Testing】文档主要涵盖了在隔离环境中设置和测试虚拟路由器(vRouter)的详细步骤,以及使用Trex测试方法进行性能评估。本文档由Intel公司的Joseph Gasparakis、Subarna Kar、Savannah ...
Isolated Storage类似于每个应用自己的私有文件系统,确保了不同应用间的数据隔离,同时保护用户数据不被其他应用访问。 备份Isolated Storage至SkyDrive是WP8用户常用的一种数据保护手段。SkyDrive(现称为One...
标题“40.5 W Non-Isolated Buck LED Driver”和描述“led驱动40.5 W, High Power Factor (-0.95), -5% IOUT Tolerance, Non-Isolated Buck LED Driver Using LinkSwitchTM-PH LNK419EG”共同指出了这款LED驱动器的...
IsolatedStorageDemo是一个用于演示.NET框架中Isolated Storage功能的源代码示例。Isolated Storage是.NET Framework提供的一种安全且受控的存储区域,它允许应用程序在用户的机器上存储数据,同时保持与其他应用...
标题中的"power_SCIG0.rar_INDUCTION GENERATOR_Isolated grid_in_isolated"表明这是一个关于交流感应发电机(Induction Generator,简称IG)在离网(Isolated Grid)环境下运行的资源包。描述简单明了,"induction ...
1、sqlserver 2012 因为卸载vs2010后无法正常使用,需要重新安装该插件
isolated-vm-访问Node.js中的多个隔离 isolated-vm是nodejs的库,可让您访问v8的Isolate接口。 这使您可以创建彼此完全隔离的JavaScript环境。 如果您需要以安全的方式运行一些不受信任的代码,则可能会发现此模块...
Troubleshooting C C++ Isolated Applications and Side-by-side Assemblies. 发现并解决C C++独立应用程序和并行程序集的问题(无法运行VS2008开发的MFCC++程序的参考)
综上所述,"Windows Phone 7 完美开发征程源代码"是一个深入学习WP7开发的宝库,无论你是刚接触这个平台的新手,还是希望提升现有技能的开发者,都能从中受益。通过实际的代码示例,你可以更好地理解和运用WP7的开发...
可以实现简单孤立词的识别和训练,内有1到9的录音,可以自己训练。
Low Noise Isolated Power Supply的设计主要基于以下几个方面: 1. 隔离输出: Low Noise Isolated Power Supply能够提供±15V的隔离输出,这使得其能够满足各种应用场景的需求。 2. 超低纹波:该电源解决方案具有...
在当今高度发达的工业自动化领域,通信技术的发展直接关系到整个生产系统的稳定性和可靠性。随着各种工业设备的广泛应用,不同类型设备间的通信兼容性问题也随之凸显。为了应对这一挑战,艾络格电子工业推出了RS232 ...
每个章节的源代码实例都是为了帮助开发者理解并掌握特定的技术,通过实际操作来巩固理论知识。这些实例可以帮助开发者逐步提升技能,最终能够独立完成Windows Phone 8应用程序的开发。通过深入研究和实践这些代码,...
源代码可能包含如何使用Bing Maps API进行地图操作和获取用户位置的代码片段。 4. **多媒体与相机支持**:WP7支持多媒体文件播放和拍照功能,开发者可以通过多媒体API实现视频录制、照片拍摄和音频播放。书中可能会...
这个官方示例代码集合针对Windows Phone 8.1版本,提供了全面的开发指导和实践案例,帮助开发者深入理解和应用各种功能。 1. **控件使用**: Windows Phone 8.1的UI设计基于XAML(Extensible Application Markup ...
在Chrome浏览器中,扩展程序(Extension)的Cookie管理机制与普通网页有所不同,这主要涉及到一个被称为"isolated cookie"的概念。这个特性确保了每个标签页内的扩展程序具有独立的Cookie存储,防止不同标签页间的...