fp = fopen("test.txt", 'ab'); //from the end
flock($fp, lock_ex); //lock the file for waiting...
fwrite($fp, 'just a test string.......'); //start writing...
flock($fp, lock_un); //release write lock
fclose($fp); //close the file读操作:
php textarea换行符的方法
涉及到textarea中的换行,因为填入的内容是base64编码之后的结果(规范规定,base64编码结果中每76个字符需要加上一个回车换行,即一个" "),在ie下测试,一切ok,但是到了firefox和谷歌浏览器下,总是提示错误,细查一下,发现不同浏览器对于换行符处理不同造成的。
两款php 截取字符串函数
<?php
header ( "content-type:text/html; charset=utf-8" );
function strcut($string, $length, $dot = '...',$charset='utf-8')
{
php字符串分割(explode str_split preg_split
php教程 explode() 函数
php string 函数
定义和用法
explode() 函数把字符串分割为数组。
语法
explode(separator,string,limit)参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。
php字符串查找 strstr preg_match
strstr("母字符串", "子字符串")用来查找子字符串在母字符串中第一次出现的位置,并返回母字符串中从子字符串开始到母字符串结束的部分。比如
php字符串比较函数
比较两个字符串是否相等,最常见的方法就是使用“===”来判断,至于它和“==”的区别,简单来说就是前者强调“identical”类型也要求一样;后者要求“equal”,值相同就可以了,参考【1】。或者使用strcmp来判断,但是这个能够告诉你两个字符串是否相等,但是无法告诉你在那里不同。我的思路是单字符串分割为一个个字母(character),这样比较就能精确知道在那个位置不同了。分隔字符串,使用“str_split”就可以了,语法参考【2】。然后输出结果数组,好处是连空格也会作为数组的元素。我之前的例子就是因为前一个字符串包含2个空格,而后一个只有一个。但是输出的时候看到的显示都是一样的。 也可以按照其他分隔符进行分割,如“explode”或者“preg_split”,
php字符串函数
addslashes: 字符串加入斜线。
bin2hex: 二进位转成十六进位。
php 读取文件函数
1、用file_get_contents或者fopen、file、readfile等函数读取url的时候,会创建一个名为$http_response_header的变量来保存http响应的报头,使用fopen等函数打开的数据流信息可以用stream_get_meta_data来获取。
php 字符串长度函数
php strlen() 函数
定义和用法
strlen() 函数返回字符串的长度。
语法
strlen(string)参数 描述
string 必需。规定要检查的字符串。
二款php文件上传程序
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="files";//设置上传域名称
foreach($_files[$f_input]["error"] as $key => $error){
$up_error="no";
if ($error == upload_err_ok){
$f_name=$_files[$f_input]['name'][$key];//获取上传源文件名
$uploadfile=$uploaddir.strtolower(basename($f_name));
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
$up_error="yes";
}
if ($_files[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_files[$f_input]
['size'][$key]/1024)."kb,大于规定的".($file_size_max/1024)."kb,上传失败!')</script>";
$up_error="yes";
}
if (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
$up_error="yes";
}
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdhis").substr($gettime[0],2,6).$rand;
$attdir="./file/";
if(!is_dir($attdir))
{ mkdir($attdir);}
$uploadfile=$attdir.$t.".".$tmp_type;
if(($up_error!="yes") and (move_uploaded_file($_files[$f_input]['tmp_name']
php filter_input函数
在 php教程5.2 中,内置了filter 模块,用于变量的验证和过滤。
过滤变量等操作可以参看我原先提及的,这里我们看下如何直接过滤用户输入的内容。
经典php分页代码(支持数字偏移)(1/2)
</style>
<?php
mysql_connect('localhost','root','');
mysql_select_db('news');
mysql_query('set names gbk');