php ftp函数文件上传
代码如下 | 复制代码 |
<?php |
一、函数的基础
php教程提供了大量的函数,并且允许用户自定函数,
php函数定义实例
代码如下 | 复制代码 |
<?php function myCount($inValue1,$inValue2) { $AddValue = $inValue1+$inValue2; return $AddValue; //返回计算结果 } $Count = myCount(59,100); echo $Count; //输出159 ?> |
函数一但被定义就可以在任何地方使用。
二、函数传参数
php 函数参数在函数定义时进行申明定义,函数可以有任意多个参数,应用最普遍的传递方法,是按值传递交的。或通过引用和默认参数值应用得相对比较少。
实例
代码如下 | 复制代码 |
<?php function myColor ($inColor = "蓝色") { return "我喜欢的颜色: $inColor. "; } echo myColor(); echo myColor("粉色"); ?> |
一般传递的值不会因函数内部改变而改变的。除非是全局变量或是引用我们来看php函数引用实例
代码如下 | 复制代码 |
<?php function str_unite (&$string) { $string .= '也喜欢蓝色.'; } $str = '喜欢红色,'; str_unite ($str); echo $str; // 输出结果: '喜欢红色,也喜欢蓝色.' ?> |
全局变量
代码如下 | 复制代码 |
<?php $a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo $b; ?> |
//搜索当前目录所有文件
代码如下 | 复制代码 |
$array = glob('*.*'); print_r($array ); |
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 2.asp教程
[4] => 3.asp
[5] => 4.aspx
[6] => 5.html
[7] => 6.php
[8] => 7.php
[9] => 8.php
[10] => 9.php
)
*/
//搜索以.php结果的php文件
代码如下 | 复制代码 |
$array = glob('*.php'); print_r($array ); |
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 6.php
[4] => 7.php
[5] => 8.php
[6] => 9.php
)
*/
//搜索包括有php,aspx 文件
代码如下 | 复制代码 |
$files = glob('*.{php,aspx}', GLOB_BRACE); print_r( $files ); /* |
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 6.php
[4] => 7.php
[5] => 8.php
[6] => 9.php
[7] => 4.aspx
)
*/
//在指定目录搜索以1开的php 文件
$files = glob('../05-15/1*.php');
print_r($files);
/*
Array
(
[0] => ../05-15/1.php
[1] => ../05-15/10.php
[2] => ../05-15/11.php
)
*/
代码如下 | 复制代码 |
//返回文件的绝对路径 $files = array_map('realpath',$files); print_r($files); |
/*
Array
(
[0] => D:wwwwww.111cn.net-15.php
[1] => D:wwwwww.111cn.net-15.php
[2] => D:wwwwww.111cn.net-15 .php
)
glob() 函数能做的事比scandir() 函数更强大,可以按照某种模式搜索文件
*/
//实例用我们用imagecreatetruecolor
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
//我把这个一起 - 结合较好的例子,然后动态生成的文本。但是,与此成立,我能得到透明背景以及工作。
//实例二imagecreatetruecolor
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';
// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);
// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
/*
实例三创建透明图片
如果你想创建一个PNG图像*透明*,其中的背景是完全透明的,所有行动发生在借鉴,除此之外,然后执行下列操作:
*/
$png = imagecreatetruecolor(800, 600);
imagesavealpha($png, true);
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
imagefill($png, 0, 0, $trans_colour);
$red = imagecolorallocate($png, 255, 0, 0);
imagefilledellips教程e($png, 400, 300, 400, 300, $red);
header("Content-type: image/png");
imagepng($png);
/*
你要做的就是创建一个真正的彩色图像,确保阿尔法保存状态是,然后填写一个颜色,也经历了阿尔法级别设置为完全透明(127)的图像。
从上面的代码产生的巴新将有一个完全透明的背景(一红色圆圈拖到Photoshop中的图像,以了解自己)
The resulting PNG from the code above will have a red circle on a fully transparent background (drag the image into Photoshop to see for yourself)
str urlencode($string)
此功能是方便的编码字符串时要在URL的查询的一部分用来作为一种方便的方法传递变量到下一页。
我写了这个简单的函数,创建一个GET查询的网址()从一个数组:
*/
function encode_array($args)
{
if(!is_array($args)) return false;
$c = 0;
$out = '';
foreach($args as $name => $value)
{
if($c++ != 0) $out .= '&';
$out .= urlencode("$name").'=';
if(is_array($value))
{
$out .= urlencode(serialize($value));
}else{
$out .= urlencode("$value");
}
}
return $out . " ";
}
//如果有在$ args数组数组,它们将被序列化之前进行了urlencoded。
echo encode_array(array('foo' => 'bar')); // foo=bar
echo encode_array(array('foo&bar' => 'some=weird/value')); // foo%26bar=some%3Dweird%2Fvalue
echo encode_array(array('foo' => 1, 'bar' => 'two')); // foo=1&bar=two
echo encode_array(array('args' => array('key' => 'value'))); // args=a%3A1%3A%7Bs%3A3%3A%22key%22%3Bs%3A5%3A%22value%22%3B%7D
/*
我需要一个在PHP函数在JavaScript中做完整的逃生功能相同的工作。我花一些时间不找到它。但findaly我决定写我自己的代码。因此,为了节省时间
*/
function fullescape($in)
{
$out = '';
for ($i=0;$i<strlen($in);$i++)
{
$hex = dechex(ord($in[$i]));
if ($hex=='')
$out = $out.urlencode($in[$i]);
else
$out = $out .'%'.((strlen($hex)==1) ? ('0'.strtoupper($hex)):(strtoupper($hex)));
}
$out = str_replace('+','%20',$out);
$out = str_replace('_','%5F',$out);
$out = str_replace('.','%2E',$out);
$out = str_replace('-','%2D',$out);
return $out;
}
//I needed encoding and decoding for UTF8 urls, I came up with these very simple fuctions. Hope this helps教程!我需要为UTF8的编码和解码网址,我想出了这些非常简单fuctions。希望这会有所帮助
function url_encode($string){
return urlencode(utf8_encode($string));
}
function url_decode($string){
return utf8_decode(urldecode($string));
}
/*
urlencode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是Baidu、Google等搜索引擎教程中输入中文查询时候,生成经过 Encode过的网页URL。urlencode的方式一般有两种一种是传统的基于GB2312的Encode(Baidu、Yisou等使用),一种是 基于utf-8的Encode(Google,Yahoo等使用)。本工具分别实现两种方式的Encode与Decode。
中文 -> GB2312的Encode -> %D6%D0%CE%C4
中文 -> utf-8的Encode -> %E4%B8%AD%E6%96%87
如果要使用utf-8的Encode,有两种方法:
一、将文件存为utf-8文件,直接使用urlencode、rawurlencode即可。
二、使用mb_convert_encoding函数。
<?php
$url = 'http://www.111cn.net/中文.rar';
echo urlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))." ";
echo rawurlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))." ";
//http%3A%2F%2Fwww.111cn.net%2F%E4%B8%AD%E6%96%87.rar
?>
相关文章
- 下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
- eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
- 在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
Jupyter Notebook读取csv文件出现的问题及解决
这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06Python astype(np.float)函数使用方法解析
这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08- 这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
- 本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
- 下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
- 这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
- 这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
- 这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
php无刷新利用iframe实现页面无刷新上传文件(1/2)
利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25- CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
- 本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
Android开发中findViewById()函数用法与简化
findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20- 要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
- 又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
- 这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18