$str = '<span style=\"font-family:\'Arial\',\'sans-serif\';font-size:9pt;\">test</span>';
//$str=stripslashes($str);
$str = preg_replace('#<([^>\s/]+)[^>]>#','<$1>',$str);
echo htmlspecialchars($str)"<br/>";
PHP正则表达式 /<adata="()"s1="()"/is 取第一和第二捕获组的数据
完整的PHP程序如下(用preg_match_all函数返回所有匹配)
<php$str = '<a id="btlist10" st="1" ditem="true" class="item multi-lines with-avatar" ftios="1" ck="TlRZNFlUSTRNakk9" ft="1" data="ABC123456" ix="10"
analytical="false" s1="ABC123" jxd1="123" jxd2="ABC123" onclick="openmenu($(this))"><a id="btlist11" st="1" ditem="true" class="item multi-lines with-avatar"
ftios="1" ck="TlRZNFlUSTRNakk9" ft="1" data="ABC123456" ix="10" analytical="false" s1="ABC123" jxd1="123" jxd2="ABC123" onclick="openmenu($(this))"><a
id="btlist12" st="1" ditem="true" class="item multi-lines with-avatar" ftios="1" ck="TlRZNFlUSTRNakk9" ft="1" data="ABC123456" ix="10" analytical="false"
s1="ABC123" jxd1="123" jxd2="ABC123" onclick="openmenu($(this))">';
preg_match_all ('/<adata="()"s1="()"/is', $str, $matches);
for ($i=0; $i<count($matches[0]); $i++) {
echo "data="$matches[1][$i]"s1="$matches[2][$i]"\n";
}
>用全局变量来解决这个问题。。
{dede:php}$GLOBALS['xxoo']=$arc->Fields['fieldname']{/dede:php}
{dede:fieldxxxx runphp="yes"}@me="test"@me"-test"$GLOBALS['xxoo'];{/dede:fieldxxxx}
即,先开一个PHP的标签,把想赋的值替换给global变量。然后在另外的运行中将field值赋值给他。
DedeCms在dede:arclist标签 如何调用附加表内容
在dede:arclist 中调用附加表内容
{dede:arclist titlelen='26' row='20' orderby='id'}
title=[field:title/]
typeid="[field:typeid/]
[field:id runphp="yes"]
$dsql = new DedeSql(false);
$a="SELECT gameassprice,gamemsg,gamebigpic,gamemodel,gamesptype,gameetime,gamebrand
FROM dede_addongame_tg as game where gameaid=@me";
$arcRow = $dsql->GetOne($a);
@me='url="'$arcRow[sptype]'" leixing="'$arcRow[model]'" pingfen="'$arcRow[assprice]'" lurl="'$arcRow[cometime]'" regurl="'$arcRow[brand]'"';
[/field:id]
info="[field:description /]
post="[field:id/]"
click="[field:click /]"
href="[field:arcurl/]"
img="<a href='[field:arcurl/]'><img src='[field:litpic/]' border='0' width='110' height='80' alt='></a>"
/>
<A href="[field:arcurl/]"><IMG height=80 alt=
src="[field:litpic/]" width=110 border=0></A>
{/dede:arclist}
[field:id runphp="yes"]
$dsql = new DedeSql(false);
$a="SELECT gameassprice,gamemsg,gamebigpic,gamemodel,gamesptype,gameetime,gamebrand
FROM dede_addongame_tg as game where gameaid=@me";
$arcRow = $dsql->GetOne($a);
@me='url="'$arcRow[sptype]'" leixing="'$arcRow[model]'" pingfen="'$arcRow[assprice]'" lurl="'$arcRow[cometime]'" regurl="'$arcRow[brand]'"';
[/field:id]
绿颜色所标地方,即是
通过ID,找到AID=ID所对应的附加表
附加表内容调用$arcRow[列名]
详细解释
以下内容只给不懂 PHP和MYSQL的人观看
[field:id runphp="yes"]
//runphp="yes" 表示 [field:id /] 里要运行 PHP程序
$dsql = new DedeSql(false);
//创建一个对象
$a="SELECT gameassprice,gamemsg,gamebigpic,gamemodel,gamesptype,gameetime,gamebrand
FROM dede_addongame_tg as game where gameaid=@me";
// 创建数据库语句,并付值给$a,
// dede_addongame_tg as game 定义表的别名为GAME
// where gameaid=@me";查询条件 gameaid=@me 其中 @ME=ID,即文章ID
$arcRow = $dsql->GetOne($a);
// 运行数据库语句并把结果放到数组$arcRow 中
@me='url="'$arcRow[sptype]'" leixing="'$arcRow[model]'" pingfen="'$arcRow[assprice]'" lurl="'$arcRow[cometime]'" regurl="'$arcRow[brand]'"';
//付值给@ME返回,这里,要想输出的值,必须付值给@me ,为了减少读取数据库的次数,这里一次把所有的结果都输出了 从数组中读取数据为$arcRow[字段名] 字段名即数据库列名如果你用LINQ-TO-XML非常方便:比如假设存在一个MyLabel的标签,里边有若干属性…… string s = "<MyLabel name='MyLabel' Text='MyText' attr1='1'/>"; var result = from e in XDocumentParse(s)Element("MyLabel"<php
$file='<div id="m"><p id="lg"><img src="/img/baidu_sylogo1gif" width="27px" height="12px" usemap="#mp"><map name="mp"><a shape="rect" coords="40,25,230,95" href="/yuanso/indexhtml" target="_blank" title="点此进入空间" ></map></p><p id="nv"><a href="/yuanso/index1html">文字1</a> <b>文字2</b> <a href="/yuanso/index3html">文字3</a></p></div>
';
$del=array("/name=+['|\"]/i","/src=+['|\"]/i","/id=+['|\"]/i","/width=+['|\"]/i","/height=+['|\"]/i","/usemap=+['|\"]/i","/shape=+['|\"]/i","/coords=+['|\"]/i","/target=+['|\"]/i","/title=+['|\"]/i");
$file = preg_replace($del,"",$file);//去除style样式
$file = str_replace(" ","",$file);//去除所有空格
$file = str_replace("<ahref=","<a href=",$file);//还原空格
echo $file;
>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)