php实际应用中一般都是用isset()函数来做判断的。
示例如下:
php实际应用中一般都是用isset()函数来做判断的。
示例如下:
//此处,$res为数组,但是数组的维数不定,此时不能用count函数
//array_filter() 将删除 $res 中所有等值为 FALSE 的条目
$filter_res = array_filter($res);
获取关键字
function get_keywords($html)
{
$html=strtolower($html);
preg_match("@<head[^>]*>(.*?)</head>@si",$html, $regs);
$headdata = $regs[1];
preg_match("/<meta +name *=["']?keywords["']? *content=["']?([^<>"]+)["']?/i", $headdata, $res);
if (isset ($res)) {
$keywords = $res[1];
}
if ($keywords == "") $keywords = "无";
$keywords=replace_word(textcut($keywords,250));
$keywords=str_replace("-",",",$keywords);
$keywords=str_replace(",",",",$keywords);
$keywords=str_replace(" ",",",$keywords);
$keywords=str_replace("|",",",$keywords);
$keywords=str_replace("、",",",$keywords);
$keywords=str_replace(",,",",",$keywords);
$keywords=str_replace("<","",$keywords);
$keywords=str_replace(">","",$keywords);
return addslashes(trim($keywords));
}
我们核心代码就是正则表达试了
function get_all_url(http://pic3.phprm.com/2013/05/18/$code.jpg){
preg_match_all(‘/<as+href=["|']?([^>"' ]+)["|']?s*[^>]*>([^>]+)</a>/i’,$code,$arr);
return array(‘name’=>$arr[2],’url’=>$arr[1]);
}
判断邮件的一个正则表达式,逐句解释下是什么意思
^(w+((-w+)|(.w+))*)+w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$
删除文件
file_delete = "home/meeta/my.php";
PHP mysql_pconnect
mysql_pconnect() 函数打开一个到 MySQL 服务器的持久连接。
数据库结构
-- phpMyAdmin SQL Dump
-- version 2.11.2-rc1
-- http://www.phprm.com
--
-- 主机: localhost
-- 生成日期: 2010 年 11 月 09 日 05:34
-- 服务器版本: 5.0.41
-- PHP 版本: 5.2.4
下面只是一个简单的实例
我们先准备mysql数据表,假设项目中有一张记录学生信息的表student,并有id,name,sex,age分别记录学生的姓名、性别、年龄等信息。
例1
<?php
$getUrl = (empty($_GET['url'])) ? './' : $_GET['url'].'/';
function fileName($dir)
{
$fileAll = scandir($dir,0);
$pathDir = $pathFile = array();
$count = count($fileAll);
if($count <= 2){
echo "空目录<br />";
}
foreach($fileAll as $pdf){
if(is_dir($dir.$pdf)){
$pathDir[] = $pdf;
}else{
$pathFile[] = $pdf;
}
}
foreach($pathDir as $pd){
if($pd == '.' or $pd == '..') continue;
echo "<a href="?url=$dir$pd">$pd</a><br />";
}
foreach($pathFile as $pf){
echo "<a href="$dir$pf" target="_blank">$pf</a><br />";
}
if($dir != './'){
$dir = rtrim($dir,'/');
$dir = explode('/',$dir);
unset($dir[sizeof($dir)-1]);
$dir = implode('/',$dir);
echo "<a href="?url=$dir">Go Back</a>";
}
}
fileName($getUrl);
题外话了,一个access转换成mysql数据库的实例