Jump to content

[SOLVED] Pear Text_highlighter


dustinnoe

Recommended Posts

I am trying to use pear's text highlighter by searching for tags in an article and highlighting the content between the tags.  Something is causing the script to crash with no errors.  Error reporting is set to E_ALL.  When there are no tags to replace the script completes and outputs the article.  Maybe I am missing something obvious but this one has me scratching my head.

 

<?php
$phpsearch = '/\<\?php(.*?)\\?\>/is';
$sqlsearch = '/\[sql\](.*?)\[\/sql\]/is';

function highlight_sql($matches){
    global $sqlsearch;
    $matches[0] = preg_replace($sqlsearch, '$1', $matches[0]);
    $sql = Text_Highlighter::factory('SQL');
    return $sql->highlight($matches[0]);
    
}

function highlight_php($matches){
    $php = Text_Highlighter::factory('php', array('tabsize' => 2));
    return $php->highlight($matches[0]);
}

$article = preg_replace_callback($phpsearch, 'highlight_php', $article);
$article = preg_replace_callback($sqlsearch, 'highlight_sql', $article);
?>

Link to comment
https://forums.phpfreaks.com/topic/73897-solved-pear-text_highlighter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.