调用 TextMagic++ API。
// Include the TextMagicPHP lib
require('textmagic-sms-api-php/TextMagicAPI.php');
// Set the username andpassword information
$username = 'myusername';
$password = 'mypassword';
// Create a new instanceof 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)
$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('{
City : ([^
}i', $content, $regs) ) {
$city = $regs[1];
}
if ( preg_match('{
State/Province : ([^
}i', $content, $regs) ) {
$state = $regs[1];
}
if( $city!='' && $state!=''){
$location = $city . ', ' .$state;
return $location;
}else{
return $default;
}
}
3. 显示网页的源代码
$lines = file('http://google.com/');
foreach ($lines as$line_num => $line) {
// loop thru each line and prepend line numbers
echo "Line # {$line_num} : " . htmlspecialchars($line) . "
\n";
}
4. 检查服务器是否使用HTTPS
if ($_SERVER['HTTPS']!= "on") {
echo "This is not HTTPS";
}else{
echo "This is HTTPS";
}
5. 显示Facebook粉丝数量
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
for ($y=0;$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
*/
// let's use up some memory
for ($i = 0; $i
$array []= md5($i);
}
// let's remove half of the array
for ($i = 0; $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 pretiumorci,
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 justoin 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错误
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line,$vars){
$email = "
An error ($number) occurred on line
$line and in the file: $file.
$message
";
$email .= "
" . print_r($vars, 1) . "
";
$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
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... (vardoesn't exist)
echo$somevarthatdoesnotexist;
摘自 战地日记_LAMP兄弟连

PHP主要是过程式编程,但也支持面向对象编程(OOP);Python支持多种范式,包括OOP、函数式和过程式编程。PHP适合web开发,Python适用于多种应用,如数据分析和机器学习。

PHP起源于1994年,由RasmusLerdorf开发,最初用于跟踪网站访问者,逐渐演变为服务器端脚本语言,广泛应用于网页开发。Python由GuidovanRossum于1980年代末开发,1991年首次发布,强调代码可读性和简洁性,适用于科学计算、数据分析等领域。

PHP适合网页开发和快速原型开发,Python适用于数据科学和机器学习。1.PHP用于动态网页开发,语法简单,适合快速开发。2.Python语法简洁,适用于多领域,库生态系统强大。

PHP在现代化进程中仍然重要,因为它支持大量网站和应用,并通过框架适应开发需求。1.PHP7提升了性能并引入了新功能。2.现代框架如Laravel、Symfony和CodeIgniter简化开发,提高代码质量。3.性能优化和最佳实践进一步提升应用效率。

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP类型提示提升代码质量和可读性。1)标量类型提示:自PHP7.0起,允许在函数参数中指定基本数据类型,如int、float等。2)返回类型提示:确保函数返回值类型的一致性。3)联合类型提示:自PHP8.0起,允许在函数参数或返回值中指定多个类型。4)可空类型提示:允许包含null值,处理可能返回空值的函数。

PHP中使用clone关键字创建对象副本,并通过\_\_clone魔法方法定制克隆行为。1.使用clone关键字进行浅拷贝,克隆对象的属性但不克隆对象属性内的对象。2.通过\_\_clone方法可以深拷贝嵌套对象,避免浅拷贝问题。3.注意避免克隆中的循环引用和性能问题,优化克隆操作以提高效率。

PHP适用于Web开发和内容管理系统,Python适合数据科学、机器学习和自动化脚本。1.PHP在构建快速、可扩展的网站和应用程序方面表现出色,常用于WordPress等CMS。2.Python在数据科学和机器学习领域表现卓越,拥有丰富的库如NumPy和TensorFlow。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Atom编辑器mac版下载
最流行的的开源编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。