模拟post数据到其它web serverfunction post_request($url, $data, $referer='') { // Convert the data array into URL Parameters like a=b&foo=bar etc. $data = http_b……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1311浏览 2837个赞
我们一般会在页面下方输出版权信息,包含年份信息,每年都要修改,这段简单的代码帮你解决这个问题,自动更新年份function autoUpdatingCopyright($startYear){ // given start year (e.g. 2004) $startYear = intval($startYear); ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2601浏览 2038个赞
一段自定义的php生成uuid的代码<?php$u=uuid(); // 0001-7f000001-478c8000-4801-47242987echo $u;echo "<br>";print_r(uuidDecode($u)); // Array ( [serverID] => 0001 [……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1898浏览 953个赞
php通过joomla jmail 类使用 gmail smtp 账号发送邮件<?phpjimport('joomla.mail.mail');$mail = new JMail();$mail->setsender("useremail");$mail->addRecipient(&q……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1516浏览 1425个赞
php上传单个文件到ftp服务器的演示范例// FTP access parameters$host = 'ftp.example.org';$usr = 'example_user';$pwd = 'example_password'; // file to move:$loca……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2800浏览 752个赞
有时候网站的www域名和非www域名都能访问网站,但是这样不利于搜索引擎的收录,会分散网页的权重,所以希望用户访问非www的域名时通过301永久重定向到www域名,例如用户访问75271.com会直接转向www.75271.com,本php代码考虑了无法通过head重定向的情况,会在页面上输出链接,让用户点击。// Install info.:// ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2134浏览 174个赞
php正则表达式功能强大,本范例演示了preg_replace_callback函数的用法// Define a dummy text, for testing...$Text = "Title: Hello world!\n";$Text .= "Author: Jonas\n";$Text .= &q……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1500浏览 2538个赞
本代码演示了php中header函数的详细用法// See related links for more status codes // Use this header instruction to fix 404 headers// produced by url rewriting...header('HTTP/1.1 200 O……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1848浏览 1903个赞
php通过查询whois信息的网站列表进行查询function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace('/^http:\/\//i'……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3109浏览 2775个赞
php获得指定范围内的最接近的数// Returns the next higher or lower numberfunction NextRelatedNumber($number, $range){ $r = $number % $range; $f = $number - $r; $b = round($r /……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2407浏览 1624个赞
php链接mysql数据库,查询范例/*** Connect to database:*/ // connect to the database$con = mysql_connect('localhost','testuser','testpassword') or di……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2988浏览 2733个赞
php使用GD创建保持宽高比的缩略图/** * Create a thumbnail image from $inputFileName no taller or wider than * $maxSize. Returns the new image resource or false on error. * Auth……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2362浏览 196个赞
本代码传入两个数组A和B,返回A-B的结果,即挑选出存在于A,但不存在于B的元素<?php function RestaDeArrays($vectorA,$vectorB) { $cantA=count($vectorA); $cantB=count($vectorB); ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2934浏览 533个赞
传入用户提交的参数时使用这段代码提供的函数先对参数进行处理,然后传入sql语句,用:mysqlquery(“INSERT INTO table VALUES(‘” . sqlsanitize($_POST[“variable”) . “‘)”);替代:mysqlq……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1478浏览 877个赞
php递归遍历删除文件,这个函数稍加修改就可以变成一个递归文件拷贝函数<? function mover($src,$dst) { $handle=opendir($src); // Opens source dir. if (!is_dir($dst)) mkdir($dst,0755); ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1319浏览 1322个赞
php阿拉伯数字和罗马数字相互转换<?php // Function that calculates the roman string to the given number: function dec2roman($f) { // Return false if eithe……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1864浏览 1558个赞
php将任意进制的数转换成10进制,例如8进制转换成10进制,16进制转换成10进制<?php # Show the steps involved in converting a number # from any base (like octal or hex) to base 10 # See below for examples,……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2510浏览 766个赞
给定一个字符串和排列组合长度生成所有可能的排列组合<? function permutations($letters,$num){ $last = str_repeat($letters{0},$num); $result = array(); while($last != str_repeat(lastchar(……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2372浏览 2348个赞
php关联数组快速排序<? function qsort($a,$f) { qsort_do(&$a,0,Count($a)-1,$f); } function qsort_do($a,$l,$r,$f) { if ($l < $r) { qsort_partit……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3118浏览 2196个赞
一个用来防止sql注入的参数检查函数function cleanuserinput($dirty){ if (get_magic_quotes_gpc()) { $clean = mysql_real_escape_string(stripslashes($dirty)); }else{ $clean = mysql_real_esca……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2633浏览 2411个赞
php中通过 func_num_args函数获取当前函数的参数数量,传入指定函数的参数数量可以是不固定的,通过func_num_args可以轻松获得参数个数function variable_argument_function () { $num_args = func_num_args(); echo ("I was passed $……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2962浏览 1666个赞
php中输出大数据文本的方法ob_start(); echo 'Put your text here'; $body = ob_get_contents();ob_end_clean(); echo $body;……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2001浏览 2805个赞
func_get_args php中用于返回指定函数的参数数量的函数,如果你想得到某个函数的参数个数的话,这个一定能帮到你。<?phpfunction foo(){ $numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2127浏览 1983个赞
可以让php随意传递参数的函数func_get_args和func_num_args php用户自定义的函数大部分是用来处理数据的,既然是处理数据那么就必然会有参数传入函数,一般的形式是这样的// function with 2 optional argumentsfuncti……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2247浏览 1211个赞
如果你需要一个随机字符串,下面这个函数正好帮你,可以自己定义长度function getCode($length=12) { //Ascii Code for number, lowercase, uppercase and special characters $no = range(48,57); $lo = range……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2255浏览 773个赞
分享一个php清除html标签的函数,用于清除不需要的html标签格式function strip_html_tags( $text ){ $text = preg_replace( array( // Remove invisible content '@<head[……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2805浏览 2715个赞
PHP连接mongodb的简单范例,改代码简单演示了php如何链接到本地mongodb数据库,并检索其中一个表的数据$connection = new Mongo( “localhost:27017” ); $collection = $connection->mydb->mycollection; $cursor = $collecti……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2804浏览 419个赞
php通过正则表达式进行字符串搜索的简单范例<?php$string_to_search = "w3mentor.com";$regex = "/tor/";$num_matches = preg_match($regex, $string_to_search); if ($num_matches ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2494浏览 2767个赞
php中 explode 和 split 函数用来分割字符串。 explode函数语法如下explode(substring, string) explode函数通过子字符串进行分割,效率比split要高 ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3008浏览 1879个赞
php中的count函数用来获得数组的长度,用法如下<?php $array = array("PHP", "Perl", "Java");print_r("Size 1: ".count($array)."\n");$array = arra……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2688浏览 2897个赞
php中可以通过ucfirst函数将一个字符串中的第一个字母转换成大写,而ucwords函数可以将一个字符串中每个单词的首字母转换成大写<?php$string = "php string functions are easy to use.";$sentence = ucfirst($string);$title = u……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2443浏览 1812个赞
php中可以通过strtolower和strtoupper两个函数将字符串中的每个英文字符全部转换成小写或者大写<?php$string = "Learn PHP string functions at 75271.com";$lower = strtolower($string);$upper = strtoupper(……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1940浏览 1543个赞
php中可以通过bin2hex函数将字符串转换成16进制的形式输出,bin2hex()函数返回结果为ascii码<?php$string = "Hello\tworld!\n";print($string."\n");print(bin2hex($string)."\n");?&g……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2956浏览 1954个赞
implode函数可以将存储在数组里的多个字符串按照指定的格式和分隔符连接成一个字符串<?php $date = array('01', '01', '2006');$keys = array('php', 'string', 'fun……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1610浏览 2990个赞
下面的代码检查一个字符串是否包含任何7位GSM字符。它对短信平台上工作的人非常有用。<?php function check_gsm($str) { $arr = array( "0x00", "0x01", "0x02", "0x03", &quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2262浏览 163个赞
php通过asort()给关联数组按照值排序,和sort的区别是,sort是按照$nums = array("one"=>5,"two"=>2,"three"=>1);asort( $nums ); foreach ( $nums as $key => $val )……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2433浏览 940个赞
array_slice(array,offset,length,preserve) array_slice() 返回根据 offset 和 length 参数所指定的 array 数组中的一段序列。如果 offset 非负,则序列将从 array 中的此偏移量开始。如果 offset 为负,则序列将从 array 中距离末端这么远的地方开始。如果给出了 ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2714浏览 1836个赞
strpos用来查找一个字符串在另一个字符串中首次出现的位置,strpos区分大小写,如果没有找到则返回false,所以strpos有两种类型的返回值,一种是整形,一种是bool型,开发过程中需要注意<?phpecho strpos("Hello world!","wo");?> ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2306浏览 2007个赞
php中包含四个可以去除字符串空格的函数:trim() – 去除字符串两端的空字符ltrim() – 去除字符串前端的空字符rtrim() – 去除字符串末尾的空字符chop() –同rtrim().<?php$text = "\t \t 75271.com!\t \t ";$leftTrimmed = ltrim(……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1898浏览 1516个赞
对strpos()函数可以用来在php中查找子字符串。strpos()函数将试图找到子字符串在源字符串中首次出现的位置。如果找到了,它会返回一个非负整数表示子字符串出现的位置。 否则它会返回一个布尔值false。<?php$haystack1 = "2349534134345w3mentor16504381640386488129&qu……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2130浏览 1830个赞
下面的代码演示了php中的函数参数如何设置和使用默认值 <html> <head> <title> Printing text on a Web Page</title> </head> <body> <?php function textonw……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3041浏览 2568个赞
php中可以通过opendir打开指定目录,读取目录下的所有文件,如果读取失败返回False<?php$dir = "PUT_PATH_TO_DIR_HERE"; // Open a known directory, and proceed to read its contentsif (is_dir($dir)) {……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1546浏览 865个赞
php通过ksort()函数给关联数组按照键排序,ksort函数按照关联数组的key正序排序,如果要倒序可以是哦那个krsort()函数$first = array("x"=>5,"a"=>2,"f"=>1);ksort( $first ); foreach ( $fir……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3205浏览 387个赞
php中可以通过function_exists()函数检测另外一个函数是否存在,可以把函数名作为一个字符串传入function_exists,判断该还是是否存在function highlight( $txt ) { return "<sub>$txt</sub>";} function textWra……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1697浏览 780个赞
php根据指定的位置和长度获得子字符串,php的substr函数功能非常强大,不断可以从前往后去子字符串还可以从后往前取字符串<?php$string = "beginning";print("Position counted from left: ".substr($string,0,5)."……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1491浏览 1620个赞