
php数组转对象,php对象转数组
数组转对象和对象转数组的方法数组转对象应用案例$array=array();$array['ss']="ssssc";$array['dd']="123d";$cc=array_to_object($array);print_r($cc);输出结果为:stdClassObject([ss]=>ssssc[dd]=>123d)数组转对象函数functionarray_to_object($arr){if(is_array($arr))...
php从HTML中获取所有图片
从HTML中获取所有图片。应用案例$txt='<p> 最近访问站点:实时显示正在使用豫唐主题或者插件的站点。</p><pstyle="text-align:center;"><imgclass="ue-image"src="https://www.ytecn.c...
php清除一串代码内所有的PHP代码
保存数据的时候,为了安全考虑,会用到这类功能,清除一串代码内所有的PHP代码。应用案例$url="1asasdasdas<?phpecho'ssss'?>";$name=RemovePHPCode($url);print_r($name);输出结果为:1asasdasdas函数functionRemovePHPCode($code){//PHPStarttags:<?php<?<?=//PHP5supports:<%<scriptlang...
php在字符串型的参数表中新加参数删除参数查询参数
字符串型的参数表加入一个新参数,从字符串型的参数表中删除一个参数,在字符串参数值查找参数。加入新参数应用案例$array="1|2|3|4";$name=AddNameInString($array,'5');print_r($name);输出结果为:1|2|3|4|5加入新参数函数functionAddNameInString($s,$name){$pl=$s;$name=(string)$name;$apl=explode('|',$pl);if(in_arr...
php获取文件权限
获取文件的权限,权限格式分为数值格式(如0644)和字符表达格式(如-rw-r--r--)两种数值格式应用案例$url="1.txt";$name=GetFilePermsOct($url);print_r($name);输出结果为:0644数值格式函数functionGetFilePermsOct($f){if(!file_exists($f)){return'';}returnsubstr(sprintf('%o',fileperms($f)),-4);}字符...
PHP获取文件后缀名
获取文件后缀名,识别当前文件是什么类型的。应用案例$url="1.txt";$name=GetFileExt($url);print_r($name);输出结果为:txt函数//@paramstring$f文件名//@returnstring返回小写的后缀名functionGetFileExt($f){if(strpos($f,'.')===false){return'';}$a=explode('.',$f);returnstrtolower(e...
获取当前目录下指定类型文件列表
获取当前目录下指定类型文件列表,比如或者txt文件,jpg文件等等。应用案例$url="D:/wwwroot/ytecn.com/txt/";$list=GetFilesInDir($url,'txt');print_r($list);输出结果为:Array([1]=>D:/wwwroot/ytecn.com/txt/1.txt[2]=>D:/wwwroot/ytecn.com/txt/2.txt)函数//@paramstring$dir目录//@paramstrin...
php获取当前目录下文件夹列表
获取当前目录下文件夹的名称应用案例$url="D:/wwwroot/ytecn.com/ui/";$list=GetDirsInDir($url);print_r($list);输出结果为:Array([0]=>code[1]=>css[2]=>img[3]=>js[4]=>tinymce)函数functionGetDirsInDir($dir){$dirs=array();if(!file_exists($dir)){returnarray();}if(!is_d...
php获取目录下文件夹列表(递归)
获取目录下所有子目录的文件夹列表(递归函数返回的是路径的全称)应用案例$url="D:/wwwroot/ytecn.com/ui/";$list=RemoveMoreSpaces($url);print_r($list);输出结果为:Array([0]=>D:/wwwroot/ytecn.com/ui/code/list[1]=>D:/wwwroot/ytecn.com/ui/code[2]=>D:/wwwroot/ytecn.com/ui/css[3]=>D:/wwwr...
php删除连续空格
对字段中的连续空格进行删除只保留一个。应用案例$txt="abcytecn1";$name=RemoveMoreSpaces($sss);echo$name;输出结果为:abcytecn1函数/***删除连续空格*@param$s*@returnnull|string|string[]*/functionRemoveMoreSpaces($s){returnpreg_replace("/\s(?=\s)/","\\1",$s);}...
php分割string并取某项数据
对string进行分割,并取某项数据。应用案例$txt="姓名|电话|手机号|豫唐";$name=SplitAndGet($txt,"|",3);echo$name;输出结果为:豫唐函数functionSplitAndGet($string,$delimiter=';',$n=0){$a=explode($delimiter,$string);if(!is_array($a)){$a=array();}if(isset($a[$n])){return(stri...
php远程提交post函数
远程提交方式:post范围:所有php类型程序函数代码functionpost($params,$url){$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_TIMEOUT,5000);curl_setopt($ch,CURLOPT_POST,true);curl_setopt($ch,CURLOPT_POSTFIELDS,$pa...
phpRSA加密解密函数
使用方法:加密$txt="ytecn";$pubkey="公钥"$macdata=RSAEncrypt::encrypt($txt,$pubkey);解密$txt="ytecn";$pubkey="私钥"$macdata=RSAEncrypt::decrypt($txt,$pubkey);类文件classRSAEncrypt{publicstaticfunctionencrypt($str,$publicKey){$pubKey=ope...
php获取网站在服务器中用的环境
判断当前网站在服务器用的什么环境functionGetWebServer(){if(!isset($_SERVER['SERVER_SOFTWARE'])){returnSERVER_UNKNOWN;}$webServer=strtolower($_SERVER['SERVER_SOFTWARE']);if(strpos($webServer,'apache')!==false){returnSERVER_APACHE;}elseif(strpos($webServe...
vscode运行php和Composer
需要用到的工具1、安装php(官网下载)2、安装composer(官网)3、vscode插件PHPServer4、vscode插件PHPDebug5、windows11系统步骤1、安装php安装包,安装后已经记录下安装路径,比如D:/BtSoft/php/80/php.exe2、配置php环境在电脑下方点击“搜索”按钮,输入“编辑系统环境变量”,然后点击。在弹出的界面点击“环境变量”双击变量“path”点击新建,输入php的安装路径D:/BtSoft/php/803、在vscode配置php安装vscode插件PH...
php将编码转换为UTF8
主要用于编码不统一导致出现乱码的情况,此函数会自动监测非UTF8编码转成UTF8编码。functionConverCode($str){$encode=mb_detect_encoding($str,array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));$newstr=mb_convert_encoding($str,'UTF-8',$encode);return$new...