---------已知 [field:softlinks/]标签可调出如下数据: |
{dede:link text= '网址名1' } http: //网址1 {/dede:link} |
{dede:link text= '网址名2' } http: //网址2 {/dede:link} |
... |
{dede:link text= '网址名n' } http: //网址n {/dede:link} |
------------想要显示的内容: |
<a href= "http://网址1" title= "网址名1" ><img src= "http://网址1.png" width= "18" height= "18" alt= "网址名1" ></a> |
<a href= "http://网址2" title= "网址名2" ><img src= "http://网址2.png" width= "18" height= "18" alt= "网址名2" ></a> |
... |
<a href= "http://网址n" title= "网址名n" ><img src= "http://网址n.png" width= "18" height= "18" alt= "网址名n" ></a> |
-----------参考代码 |
[field:softlinks runphp= 'yes' ] |
$link = array_filter(explode( '{/dede:link}' ,@me ), "filter" ); |
$len = count( $link ); |
for ( $i=0;$i< $len-1;$i++ ) |
{ |
$tpattern= "/{dede:link text='(.*)'}/i" ; |
$ppattern= "/'}(.*)/i" ; |
preg_match_all($tpattern,$link[$i],$title); |
preg_match_all($ppattern,$link[$i],$path); |
echo '<a href=' .$path[1][0]. ' >' .$title[1][0]. '</a>' ; |
} |
function filter($var) |
{ |
if ($var == '' || $var == ' ' ) |
{ |
return false ; |
} |
return true ; |
} |
[/field:softlinks] |
---------这个写的有问题 怎么修改 |
想尽量在一个 [field:softlink php处理中 调出结果 里边应该用到 循环匹配 一次调用的 网址 网址名数据 并插入到要实现的格式中 |
我稍微改了下 |
[field:softlinks runphp= 'yes' ] |
preg_match_all( '/=\'(.+?)\'} (.+?) {/sim' , @me, $strResult, PREG_PATTERN_ORDER); |
$a=$strResult[1][0]; |
$b=$strResult[2][0]; |
@me= '<a class=tooltip href=' .$b. ' title=' .$a. '><img src=' .$b. '.png width=18 height=18 alt=' .$a. '></a>' ; |
[/field:softlinks] |
不过这是第 0条数据 要取 {/dede:link}数据出现的次数 然后 i++循环下 这个不会写 |
固定的写法 但这样 循环次数就固定成4组了 |
[field:softlinks runphp= 'yes' ] |
preg_match_all( '/=\'(.+?)\'} (.+?) {/sim' , @me, $strResult, PREG_PATTERN_ORDER); |
@me= ' |
<a class =tooltip href= '.$strResult[2][0].' title= '.$strResult[1][0].' ><img src= '.$strResult[2][0].' .png width=18 height=18 alt= '.$strResult[1][0].' ></a> |
<a class =tooltip href= '.$strResult[2][1].' title= '.$strResult[1][1].' ><img src= '.$strResult[2][1].' .png width=18 height=18 alt= '.$strResult[1][1].' ></a> |
<a class =tooltip href= '.$strResult[2][2].' title= '.$strResult[1][2].' ><img src= '.$strResult[2][2].' .png width=18 height=18 alt= '.$strResult[1][2].' ></a> |
<a class =tooltip href= '.$strResult[2][3].' title= '.$strResult[1][3].' ><img src= '.$strResult[2][3].' .png width=18 height=18 alt= '.$strResult[1][3].' ></a> |
' ; |
[/field:softlinks] |
[field:softlinks runphp= 'yes' ] |
preg_match_all( '/=\'(.+?)\'} (.+?) {/sim' , @me, $strResult, PREG_PATTERN_ORDER); |
$aaa=array(); |
for ($p=0;$p<count($strResult[0]);$p++){ |
$aaa[]= '<a class=tooltip href=' .$strResult[2][$p]. ' title=' .$strResult[1][$p]. '><img src=' .$strResult[2][$p]. '.png width=18 height=18 alt=' .$strResult[1][$p]. '></a>' ; |
} |
$aaa=implode( '' ,$aaa); |
@me=$aaa; |
[/field:softlinks] |