把FCKeditor导入PHP+SMARTY的方法
提取Fckeditor时,采用如下
PHP用$_POST['p_info']得到FCKeditor的值
补充:
1 .此处basepath 的路径一定要和上面include的路径一样.否则会找不到文件)
另外,对于这个输入内容的变量,如果要把它存入数据库教程,它的变量名为你建
立对象的名字.例如上面就是 "p_info"
2. 在FCKeditor/_samples/里面有个php教程调用的例子.如simples01.php
和sampleposteddata.php这两个.后面那个文件是输出变量名的php
程序,通过这个程序可以得到文本输入框内容的变量名.
3. 配置 FCKeditor的toolbar功能按钮可以很容易地进行定制,你可以依据你
的需要在FCKeditor的配置文件FCKeditor/fck_config.js中进行定制
一个功能按钮对应一个唯一的名称。
在fck_config.js中默认情况下已经设定好三种toolbar样式:Default(包
含全部功能),Accessibility和Basic。
让我们先来看看toolbar样式的定制格式:
config.ToolbarSets["ToolBarSetName"] = [ // Toolbar名
['Item 1','Item 2','-','Item 3','Item n'], // Toolbar第一行
['Item 4','-','Item 5','Item 6','Item n'] // Toolbar第二行
] ;
这里'-'的作用是创建一个分割条。
实例
<?
$BasePath = "../include/FCKeditor/" ;
include( $BasePath . "fckeditor.php" );$fck = new FCKeditor ( 'p_info' ) ;//建立对像
$fck -> BasePath = $BasePath ;//Fckeditor所在的位置
$fck -> ToolbarSet = 'News' ;//News为自定义的Fckeditor工具栏名称
$fck -> Width = '700' ;//长度
$fck -> Height = '350' ;//高度
$fck -> Config [ 'AutoDetectLanguage' ] = false ;//语言自动检测
$fck -> Config [ 'DefaultLanguage' ]= 'zh-cn' ;//语言
$content = $fck -> CreateHtml ();//创建Fckeditor脚本文件
$smarty -> assign ( 'content' , $content );
$smarty -> display ( "fck.tpl" );
?>
在smarty的文件中需要显示的地方
<tr align="left">
<td colspan="2" valign="top" bgcolor="#F5F5F5" class="font12en">
<{$content}>
</td>
</tr>
默认的Default包含了FCKeditor的全部功能,个人感觉有些功能用不上,完全加载还会影响显示速度,所以我简化了一下,只加载了一些常用的功能:
1、打开FCKeditor/fck_config.js文件
使用时只需把$oFCKeditor->ToolbarSet = 'Default'
改为$oFCKeditor->ToolbarSet = 'www' 即可
最后.我们把FCKeditor目录下所有以下划线“_”开头的目录都删掉以节省空间,如_test._samples
仿淘宝商品详细页加入购物车效果
goods.dwt页面 <a href="网页特效:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默认的链接有点点区别 大家对比添加
要显示的层添加到这个叶面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">关闭</a></div>
<div class="mesgCon">
<h3>宝贝已成功添加到购物车!</h3>
<div>购物车共有<span id="ECS_GOODS_NUMBER"></span>种商品 合计:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
复制代码
我把样式也贴出来 供大家参考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
复制代码
打开js/common.js文件 修改 addToCart函数 修改后:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php教程?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
复制代码
添加几个js函数 /* *
* 处理添加商品到购物车的反馈信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺货登记,跳转
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 没选规格,弹出属性选择框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
复制代码
打开flow.php 167行左右添加 /* 取得商品列表,计算合计 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
复制代码
根据以上操作可实现 效果大家应该都知道 如图:实现方法:
goods.dwt页面 <a href="javascript:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默认的链接有点点区别 大家对比添加
要显示的层添加到这个叶面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">关闭</a></div>
<div class="mesgCon">
<h3>宝贝已成功添加到购物车!</h3>
<div>购物车共有<span id="ECS_GOODS_NUMBER"></span>种商品 合计:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
复制代码
我把样式也贴出来 供大家参考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
复制代码
打开js/common.js文件 修改 addToCart函数 修改后:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
复制代码
添加几个js函数 /* *
* 处理添加商品到购物车的反馈信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺货登记,跳转
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 没选规格,弹出属性选择框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
复制代码
打开flow.php 167行左右添加 /* 取得商品列表,计算合计 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
复制代码
根据以上操作可实现
实现方法:
goods.dwt页面 <a href="javascript:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默认的链接有点点区别 大家对比添加
要显示的层添加到这个叶面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">关闭</a></div>
<div class="mesgCon">
<h3>宝贝已成功添加到购物车!</h3>
<div>购物车共有<span id="ECS_GOODS_NUMBER"></span>种商品 合计:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
复制代码
我把样式也贴出来 供大家参考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
复制代码
打开js/common.js文件 修改 addToCart函数 修改后:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
复制代码
添加几个js函数 /* *
* 处理添加商品到购物车的反馈信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺货登记,跳转
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 没选规格,弹出属性选择框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
复制代码
打开flow.php 167行左右添加 /* 取得商品列表,计算合计 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
复制代码
根据以上操作可实现
实现方法:
goods.dwt页面 <a href="javascript:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默认的链接有点点区别 大家对比添加
要显示的层添加到这个叶面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">关闭</a></div>
<div class="mesgCon">
<h3>宝贝已成功添加到购物车!</h3>
<div>购物车共有<span id="ECS_GOODS_NUMBER"></span>种商品 合计:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
复制代码
我把样式也贴出来 供大家参考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
复制代码
打开js/common.js文件 修改 addToCart函数 修改后:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
复制代码
添加几个js函数 /* *
* 处理添加商品到购物车的反馈信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺货登记,跳转
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 没选规格,弹出属性选择框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//购物车提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
复制代码
打开flow.php 167行左右添加 /* 取得商品列表,计算合计 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
使android也支持php教程做法
Android 搭建PHP WEB服务器 前几天玩Android发现个好玩的东西,
到GOOGLE市场搜索paw server 安装
找到插件,里面有个PHP插件,下载之后解压如插件目录,
建立一个PHP文件,放入/sdcard/paw/html/ WEB访问,
可以解析PHP文件哦
呵呵,不过只支持sqlite数据库教程和少量扩展
除非你的android开ROOT了,运行paw以root身份运行,不的话80使用不了的,这是linux 的限制
在装一个ftp server ,在android市场里有很多类似软件,自己下来装一个吧
在安装一个dyndns客户端,申请个帐号,二级域名的动态DNS解析是免费的,路由做好端口转发,一个在手机上的PHP 服务器搭建完毕
PHP CLI SAPI 允许您开发 PHP 支持的 shell 脚本,甚至是基于桌面的脚本。事实上,可以用PHP命令行运行的工具。采用这种方式,PHP 开发人员可以像 Perl、AWK、Ruby 或 shell 程序员一样高效。本文探究构建到 PHP 中的工具,让您了解 PHP 运行的底层 shell 环境和文件系统。PHP 为执行外部命令提供大量函数,其中包括 shell_exec()、exec()、passthru() 和 system()。这些命令是相似的,但为您运行的外部程序提供不同的界面。所有这些命令都衍生一个子进程,用于运行您指定的命令或脚本,并且每个子进程会在命令输出写到标准输出 (stdout) 时捕捉它们。
shell_exec()
清单 1. 使用反撇号计算单词数量
复制代码 代码如下:
#! /bin/sh
number_of_words=`wc -w *.txt`
echo $number_of_words#result would be something like:
#165 readme.txt 388 results.txt 588 summary.txt
#and so on....
在您的 PHP 脚本中,您可以在 shell_exec() 中运行这个简单的命令,如清单 2 所示,并获取想要的结果。这里假设在同一个目录下有一些文本文件。
清单 2. 在 shell_exec() 中运行相同的命令
复制代码 代码如下:
<?php教程
$results = shell_exec('wc -w *.txt');
echo $results;
?>
在图 1 中可以看到,获得的结果与从 shell 脚本得到的一样。这是因为 shell_exec() 允许您通过 shell 运行外部程序,然后以字符串的形式返回结果。
图 1. 通过 shell_exec() 运行 shell 命令的结果
注意,仅使用后撇号操作符也会得到相同的结果,如下所示。
清单 3. 仅使用后撇号操作符
复制代码 代码如下:
<?php
$results = `wc -w *.txt`;
echo $results;
?>
清单 4 给出了一种更加简单的方法。
清单 4. 更加简单的方法
复制代码 代码如下:
<?php
echo `wc -w *.txt`;
?>
通过 UNIX 命令行和 shell 脚本能够完成很多东西,知道这点很重要。例如,您可以使用竖线将命令连接起来。您甚至可以使用操作符在其中创建 shell 脚本,并且仅调用 shell 脚本(根据需要使用或不使用参数)。
例如,如果您仅希望计算该目录下的前 5 个文本文件的单词数,那么可以使用竖线 (|) 将 wc 和 head 命令连接起来。另外,您还可以将输出结果放到 pre 标记内部,让它能够更美观地呈现在 Web 浏览器中,如下所示。
清单 5. 更加复杂的 shell 命令
复制代码 代码如下:
<?php
$results = shell_exec('wc -w *.txt | head -5');
echo "<code lang="php">".$results . "</code>";
?>
图 2 演示了运行清单 5 的脚本得到的结果。
图 2. 从 shell_exec() 运行更复杂的 shell 命令得到的结果
在本文的后面部分,您将学习如何使用 PHP 为这些脚本传递参数。现在您可以将它看作运行 shell 命令的一种方法,但要记住您只能看到标准输出。如果命令或脚本出现错误,您将看不到标准的错误 (stderr),除非您通过竖线将它添加到 stdout。
官网参考
<?php
define("__USED_CHARS__", "abcdefghijklmnopqrstuvwxyz0123456789");
define("__CASE_SENSITIVE__", true); // Use string above or use uppercase / lowercase variant$bf = new chargen(2); // new chargen object, length 2
$bf->generate("whois"); // generate chars and call whois functionfunction whois($str)
{
$domain = $str.".com";$retval = shell_exec("whois $domain");
if (eregi("no match", $retval))
echo $domain." ist availablen";
else
echo $domain." is unavailablen";
}class chargen
{
private $chars = NULL;
private $maxlength = NULL;protected $buffer = NULL;
function generate($mycallback = false)
{
foreach ($this->buffer as $char)
{
foreach ($this->chars as $nextchar)
{
$retval = $char.$nextchar;
$this->buffer[$retval] = $retval;if ($mycallback && function_exists($mycallback))
$mycallback($retval);
else
echo $retval."n";
}
}if (strlen($retval) == $this->maxlength)
return;$this->generate($mycallback);
}function __construct($maxlength = 8)
{
$chars = array();$this->buffer = array();
array_push($this->buffer, "");for ($i = 0; $i < strlen(__USED_CHARS__); $i++)
{
$index = substr(__USED_CHARS__, $i, 1);if (__CASE_SENSITIVE__)
{
$this->chars[$index] = $index;
}
else
{
$this->chars[strtolower($index)] = strtolower($index);
$this->chars[strtoupper($index)] = strtoupper($index);
}
}$this->maxlength = $maxlength;
}
}
?>
php教程 类中多态的应用
Instanceof:用来测定一个给定的对象是否来自指定的对象类
<?php
class A{}
class B{}
$thing=new A();
//return true
if ($thing instanceof A) {
echo 'A';
}
//return false
if ($thing instanceof B) {
echo 'B';
}
?>
运行结果:
A
<?php
header("Content-Type:text/html;charset=UTF-8");
interface MyUsb{
function type();
function alert();
}
class Zip implements MyUsb{
function type(){
echo "2.0";
}
function alert(){
echo "正在检查U盘驱动";
}
}
class Mp3 implements MyUsb{
function type(){
echo "1.0";
}
function alert(){
echo "正在检查Mp3驱动";
}
}
class Mypc{
function PcUsb($what)
{
$what->type();
$what->alert();
}
}
$pc=new Mypc();
$zip=new Zip();
$mp3=new Mp3();
$pc->PcUsb($zip);//当插上的是U盘的时候
echo "<br/>";
$pc->PcUsb($mp3);//当插上的是MP3的时候
?>
运行结果:
2.0正在检查U盘驱动
1.0正在检查Mp3驱动
对象引用都是一样的不分父类引用,还是子类引用。 我们现在来看一个例子,首先还是要使用多态就要有父类对象和子类对象的关系。做一 个形状的接口或是抽象类做为父类,里面有两个抽象方法,一个求周长的方法,另一个是求 面积的方法;这接口的子类是多种不同的形状,每个形状又都有周长和面积,又因为父类是 一个接口,所以子类里面就必须要实现父类的这两个周长和面积的抽象方法,这样做的目的 是每种不同形状的子类都遵守父类接口的规范,都要有求周长和求面积的方法。
代码如下:
<?
//定义了一个形状的接口,里面有两个抽象方法让子类去实现
interface Shape{
function area();
function perimeter();
}
//定义了一个矩形子类实现了形状接口中的周长和面积
class Rect implements Shape{
private $width;
private $height;
function __construct($width, $height){
$this->width=$width;
$this->height=$height;
}
function area(){
return "矩形的面积是:".($this->width*$this->height);
}
function perimeter(){
return "矩形的周长是:".(2*($this->width+$this->height));
}
}
//定义了一个圆形子类实现了形状接口中的周长和面积
class Circular implements Shape{
private $radius;
function __construct($radius){
$this->radius=$radius;
}
function area(){
return "圆形的面积是:".(3.14*$this->radius*$this->radius);
}
function perimeter(){
return "圆形的周长是:".(2*3.14*$this->radius);
}
}
//把子类矩形对象赋给形状的一个引用
$shape=new Rect(5, 10);
echo $shape->area()."<br>";
echo $shape->perimeter()."<br>";
//把子类圆形对象赋给形状的一个引用
$shape=new Circular(10);
echo $shape->area()."<br>";
echo $shape->perimeter()."<br>";
?>
上例执行结果:
执行结果
矩形的面积是:50
矩形的周长是:30
圆形的面积是:314
圆形的周长是:62.8
通过上例我们看到,把矩形对象和圆形对象分别赋给了变量$shape,调用$shape 引用中
的面积和周长的方法,出现了不同的结果,这就是一种多态的应用,其实在我们PHP 这种弱
类形的面向对象的语言里面,多态的特性并不是特别的明显,其实就是对象类型变量的变项
应用。
相关文章
php 中file_get_contents超时问题的解决方法
file_get_contents超时我知道最多的原因就是你机器访问远程机器过慢,导致php脚本超时了,但也有其它很多原因,下面我来总结file_get_contents超时问题的解决方法总结。...2016-11-25- php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
- 相信很多站长都遇到过这样一个问题,访问页面时出现408错误,下面一聚教程网将为大家介绍408错误出现的原因以及408错误的解决办法。 HTTP 408错误出现原因: HTT...2017-01-22
- 下面我们来看一篇关于Android子控件超出父控件的范围显示出来方法,希望这篇文章能够帮助到各位朋友,有碰到此问题的朋友可以进来看看哦。 <RelativeLayout xmlns:an...2016-10-02
- ps软件是现在非常受大家喜欢的一款软件,有着非常不错的使用功能。这次文章就给大家介绍下ps把文字背景变透明的操作方法,喜欢的一起来看看。 1、使用Photoshop软件...2017-07-06
- 1.在没有设置默认值的情况下: 复制代码 代码如下:SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_timeFROM userinfoLEFT JOIN region ON userinfo.adm_regionid = region.id 结果:...2014-05-31
intellij idea快速查看当前类中的所有方法(推荐)
这篇文章主要介绍了intellij idea快速查看当前类中的所有方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-09-02js导出table数据到excel即导出为EXCEL文档的方法
复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ht...2013-10-13- 批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
- ps软件是一款非常不错的图片处理软件,有着非常不错的使用效果。这次文章要给大家介绍的是ps怎么制作倒影,一起来看看设计倒影的方法。 用ps怎么做倒影最终效果̳...2017-07-06
- 本文涉及的主题虽然很基础,在许多人看来属于小伎俩,但在JavaScript基础知识中属于一个综合性的话题。这里会涉及到对象属性的封装、原型、构造函数、闭包以及立即执行表达式等知识。公有方法 公有方法就是能被外部访问...2015-11-08
安卓手机wifi打不开修复教程,安卓手机wifi打不开解决方法
手机wifi打不开?让小编来告诉你如何解决。还不知道的朋友快来看看。 手机wifi是现在生活中最常用的手机功能,但是遇到手机wifi打不开的情况该怎么办呢?如果手机wifi...2016-12-21- 最近想自学PHP ,做了个验证码,但不知道怎么搞的,总出现一个如下图的小红叉,但验证码就是显示不出来,原因如下 未修改之前,出现如下错误; (1)修改步骤如下,原因如下,原因是apache权限没开, (2)点击打开php.int., 搜索extension=ph...2013-10-04
- 单个字符分割 string s="abcdeabcdeabcde"; string[] sArray=s.Split('c'); foreach(string i in sArray) Console.WriteLine(i.ToString()); 输出下面的结果: ab de...2020-06-25
- javascript控制页面控件隐藏显示的两种方法,方法的不同之处在于控件隐藏后是否还在页面上占位 方法一: 复制代码 代码如下: document.all["panelsms"].style.visibility="hidden"; document.all["panelsms"].style.visi...2013-10-13
连接MySql速度慢的解决方法(skip-name-resolve)
最近在Linux服务器上安装MySql5后,本地使用客户端连MySql速度超慢,本地程序连接也超慢。 解决方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。原因是默认安装的MySql开启了DNS的反向解析。如果禁用的话就不能...2015-10-21- 本篇文章是对C#方法进行了详细的总结与介绍,需要的朋友参考下...2020-06-25
- 步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
- EXCEL数据上传到SQL SERVER中的方法需要注意到三点!注意点一:要把EXCEL数据上传到SQL SERVER中必须提前把EXCEL传到服务器上.做法: 在ASP.NET环境中,添加一个FileUpload上传控件后台代码的E.X: 复制代码 代码如下: if...2013-09-23
- mysql锁定单个表的方法 复制代码 代码如下:mysql>lock table userstat read; mysql>unlock tables; 页级的典型代表引擎为BDB。 表级的典型代表引擎为MyISAM,MEMORY以及很久以前的ISAM。 行级的典型代表引擎为INN...2014-05-31