正则表达式提取网址中的id
PHP的正则表达式提取图片地址的代码。
正则表达式提取网址中的id
PHP的正则表达式提取图片地址的代码。
在 ecshop 二次开发中做产品分类索引时,要根据分类 id 取得所属顶级分类 id 。第一个反应就是用递归递出来,于是写了递归函数如下:
function getCatTopId($cat_id)
{
if ($cat_id)
{
$res = Array();
$sql = 'SELECT cat_id, parent_id'
. ' FROM ' . $GLOBALS['ecs']->table('category')
. ' WHERE cat_id = ' . $cat_id . ' AND is_show = 1';
变量的引用
PHP 的引用允许你用两个变量来指向同一个内容
数据库结构我们只要
无平台限制
只需要告知id,parentid,name 即可
众所周知,http协议是一个无状态协议,简单来说就是,web服务器是不知道现在连接上来的人到底是哪个人,为了满足选择性发送信息的需求,在http的基础上做了很多扩展来达到这个目的,如数字签名、cookie、session等。
web服务器或者web程序如何能够知道现在连接上来的是谁?要解决这个问题,首先需要在服务器端和客户端建立一一对应关系,下边我通过抓取http的内容来说明这种对应关系是如何建立的。
我使用的是一个叫做httplook的http包嗅探工具,然后在本地web服务器的根目录下建立一个叫test.php的文件,地址是:http://localhost/test.php,一切就绪以后我通过浏览器反复打开这个页面。
array_slice() 第一个参数是要切割的数组,第二个参数是起始位置,第三个参数是长度。
就是 切割 $arr这个数组,从第0个元素往后数3个。
<?php
include_once('PHPExcel.php');
//read excel file;
$PHPExcel = new PHPExcel();
$PHPReader = new PHPExcel_Reader_Excel5();
$PHPExcel = $PHPReader->load('/home/yuanjianjun/taobao_cat.xls');
$currentSheet = $PHPExcel->getSheet(0);
$allColumn = $currentSheet->getHighestColumn();
$allRow = $currentSheet->getHighestRow();
for($currentRow = 1; $currentRow<=$allRow; $currentRow++){
for($currentColumn='A'; $currentColumn<=$allColumn; $currentColumn++){
$address = $currentColumn.$currentRow;
echo $currentSheet->getCell($address)->getValue()."t";
}
echo "n";
}
<?php
/**
* 逆序二维数组插入一元素
*
* @author WadeYu
* @date 2012-05-30
*/
$aSorted = array(
array(1, 100),
array(2, 90),
array(3, 80),
array(4, 70),
array(5, 60),
array(6, 50),
array(7, 40),
array(8, 40),
array(9, 40),
array(10, 20),
);
$aInsert = array(11, 40);
$maxCmpIdx = 0;
$cnt = 0;
$maxCnt = 10;
foreach ($aSorted as $idx => $arr){
if ($arr[0] == $aInsert[0]){
$maxCmpIdx = $idx;
}
$cnt++;
}
if ( !$maxCmpIdx){
$maxCmpIdx = $cnt++;
}
$aSorted[$maxCmpIdx] = $aInsert;
for ($i = $maxCmpIdx; $i > 0; $i--){
if ($aSorted[$i][1] > $aSorted[$i-1][1]){
$aTmp = $aSorted[$i-1];
$aSorted[$i-1] = $aSorted[$i];
$aSorted[$i] = $aTmp;
continue ;
}
break;
}
for ($i = $cnt; $i > $maxCnt; $i--){
unset($aSorted[$i-1]);
}
print_r($aSorted);