PHP Converendo texto em HTML

PHP Converendo texto em HTML

$part) {
        $parts[$key] = substr($string, $pos, strlen($part));
        $pos += strlen($part) + strlen($find);
    }

    return (join($replace, $parts));
}

function txt2html($txt) {
    // Transforms txt in html

    //Kills double spaces and spaces inside tags.
    if (!(strpos($txt, '  ') === FALSE))
        $txt = str_replace('  ', ' ', $txt);
    $txt = str_replace(' >', '>', $txt);
    $txt = str_replace('< ', '<', $txt);

    //Transforms accents in html entities.
    $txt = utf8_decode($txt);
    $txt = htmlentities($txt);

    //We need some HTML entities back!
    $txt = str_replace('"', '"', $txt);
    $txt = str_replace('<', '', $txt);
    $txt = str_replace('&', '&', $txt);

    //Ajdusts links - anything starting with HTTP opens in a new window
    $txt = stri_replace("<a href="http://", "<a target="_blank" href="http://", $txt);
    $txt = stri_replace("<a href=http://", "<a target="_blank" href=http://", $txt);

    //Basic formatting
    $eol = (strpos($txt, "r") === FALSE) ? "n" : "rn";
    $html = '

'.str_replace("$eol$eol", "

", $txt).'

';
    $html = str_replace("$eol", "n", $html);
    $html = str_replace("

", "

nn", $html);
    $html = str_replace("


", "

 

", $html);

    //Wipes  after block tags (for when the user includes some html in the text).
    $wipebr = Array("table", "tr", "td", "blockquote", "ul", "ol", "li");

    for ($x = 0; $x < count($wipebr); $x++) {

        $tag = $wipebr[$x];
        $html = stri_replace("", "", $html);
        $html = stri_replace("", "", $html);

    }

    return $html;
}
?>

No related posts.

Leave a Reply





Visite também minha página pessoal www.flaviozantut.com