php span标签什么意思,使用PHP使用SPAN包装锚标记内容

我需要在PHP(Joomla 1.5)中生成一些简单的UL标记,并用SPAN标记包装每个锚标记的文本内容。传入的HTML如下所示:

输出需要如下所示:

另请注意,该类添加到活动LI标记(“selected”),并且该类添加到列表中的最后一个(“nav-last”)。这是在Joomla 1.5中,我将覆盖主菜单使用的mod_mainmenu模块。代码使用SimpleXML库来读取和写入modMainMenuXMLCallback(&$node, $args)中的HTML:

defined('_JEXEC') or die('Restricted access');

if ( ! defined('fancyMenuPatch') )

{

function fancyMenuPatch($result,$tag){

// Replace UL tag with ours.

// Replace LI tag with ours.

// Add to the start of the UL tag.

$begin_ul = "

  • ";

$begin_li = "

"; //not sure what to do with this.

// do the replacement

$result = str_replace("

  • ",$begin_ul, $result);

$result = str_replace("

", $begin_li, $result);

return $result;

}

define('fancyMenuPatch', true);

}

if ( ! defined('modMainMenuXMLCallbackDefined') )

{

function modMainMenuXMLCallback(&$node, $args)

{

$user = &JFactory::getUser();

$menu = &JSite::getMenu();

$active = $menu->getActive();

$path = isset($active) ? array_reverse($active->tree) : null;

if (($args['end']) && ($node->attributes('level') >= $args['end']))

{

$children = $node->children();

foreach ($node->children() as $child)

{

if ($child->name() == 'ul') {

$node->removeChild($child);

}

}

}

if ($node->name() == 'ul') {

foreach ($node->children() as $child)

{

if ($child->attributes('access') > $user->get('aid', 0)) {

$node->removeChild($child);

}

}

}

if (($node->name() == 'li') && isset($node->ul)) {

$node->addAttribute('class', 'parent');

}

if (isset($path) && (in_array($node->attributes('id'), $path) || in_array($node->attributes('rel'), $path)))

{

if ($node->attributes('class')) {

$node->addAttribute('class', $node->attributes('class').' active');

} else {

$node->addAttribute('class', 'active');

}

}

else

{

if (isset($args['children']) && !$args['children'])

{

$children = $node->children();

foreach ($node->children() as $child)

{

if ($child->name() == 'ul') {

$node->removeChild($child);

}

}

}

}

if (($node->name() == 'li') && ($id = $node->attributes('id'))) {

if ($node->attributes('class')) {

$node->addAttribute('class', $node->attributes('class').' item'.$id);

} else {

$node->addAttribute('class', 'item'.$id);

}

}

if (isset($path) && $node->attributes('id') == $path[0]) {

$node->addAttribute('id', 'current');

} else {

$node->removeAttribute('id');

}

$node->removeAttribute('rel');

$node->removeAttribute('level');

$node->removeAttribute('access');

}

define('modMainMenuXMLCallbackDefined', true);

}

ob_start();

modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');

$menu_html = ob_get_contents();

ob_end_clean();

if($params->get('menutype')=="primarynav"){

$tag = $params->get('tag_id');

}

//output the menu!

echo fancyMenuPatch($menu_html,$tag);

?>

谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值