Joomla trim 一 class

Joomla trim a class

大家好,我收到了这个代码

<?php if($this->item->params->get('itemRelatedIntrotext')): ?>
            <div class="itemRelIntrotext"><?php $new_string = substr($item->introtext, 0, 220); echo $new_string; ?></div>
            <?php endif; ?>

带来了内文,但它带来了带有所有 html 代码的文本

<p class="mmbodytext">Dentro del <strong>Plan Estratégico</strong> de la campaña y como una de las líneas de acción de la comunicación está el <strong>Marketing Online</strong>. Su función, educar una...</p>

调用文本时,我需要删除 class="mmbodytext" 并从中删除

想清楚...

<?php if($this->item->params->get('itemRelatedIntrotext')): ?>
            <div class="itemRelIntrotext"><?php $new_string = substr($item->introtext, 0, 220); ?>
            <?php $string = $new_string;
                $wordlist = array("mmbodytext","<strong>");

                foreach ($wordlist as $word) {
                    $string =str_replace($word, '', $string);
                }
                echo $string;
                ?>
            </div>
            <?php endif; ?>

如果您正在寻找一种简单的方法来删除所有标签,您可以使用 strip_tags()

<?php echo substr(strip_tags($item->introtext), 0, 220); ?>

参考:strip_tags