Jump to content

retirar comentários-php


fil79
 Share

Recommended Posts

Boas

Num site que estou a fazer, uso um WISIWYG (tiny mc) para inserir texto numa tabela(no backoffice), texto que posteriormente vai ser mostrado ao utilizador no site em causa. Acontece que estes utilitários criam algum lixo no html e gostaria de o limpar aquando do seu output na página, nomeadamente de tirar os muitos comentários que esta cria, e gostaria de saber que função em php devo usar para retirar os comentários.

    <?=($linha['texto'])?>

Desde já agradeço

MCITP-MCTS-MCP

Link to comment
Share on other sites

RESOLVIDO

consegui usando a seguinte função:

<?php
function strip_only($str, $tags) {
    if(!is_array($tags)) {
        $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
        if(end($tags) == '') array_pop($tags);
    }
    foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
    return $str;
}

$str = '<p style="text-align:center">Paragraph</p><strong>Bold</strong><br/><span style="color:red">Red</span><h1>Header</h1>';

echo strip_only(utf8_encode($linha['descricao']), array('!'));
?>

MCITP-MCTS-MCP

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.