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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.