| Recently, I had a problem with the Text Highlighter | | | | $hiHtml->setRenderer($renderer); |
| obtained from the PHP PEAR repository. I thought I | | | | $hiCss =& Text_Highlighter::factory("CSS"); |
| was following all the instructions but it seemed the | | | | $hiCss->setRenderer($renderer); |
| code was not highlighting the text with color (i.e. | | | | $hiPhp =& Text_Highlighter::factory("PHP"); |
| beautifying it). Here are the steps I took to get the | | | | $hiPhp->setRenderer($renderer); |
| Text_Highlighter working on this site: | | | | $hiDtd =& Text_Highlighter::factory("DTD"); |
| 1) First you need to install the PEAR | | | | $hiDtd->setRenderer($renderer); |
| TEXT_HIGHLIGHTER. Google 'pear php.' Then search | | | | $hiJava =& Text_Highlighter::factory("Java"); |
| for 'text highlighter.' | | | | $hiJava->setRenderer($renderer); |
| Type this: pear install Text_Highlighter-0.7.1 (or | | | | $hiJavascript =& |
| whatever is the latest, stable version and replace | | | | Text_Highlighter::factory("Javascript"); |
| with the appropriate numbers). I had a problem with | | | | $hiJavascript->setRenderer($renderer); |
| where I currently host some of my websites. I ran | | | | $hiMySql =& Text_Highlighter::factory("MySQL"); |
| this pear install Text_Highlighter-0.7.1 via | | | | $hiMySql->setRenderer($renderer); |
| PuTTY;however, I received an error that the Text | | | | $hiPerl =& Text_Highlighter::factory("Perl"); |
| Highlighter files could not be found. So I attempted to | | | | $hiPerl->setRenderer($renderer); |
| change the php.ini file on the line include_path but it | | | | $hiPython =& |
| didn't work. So I used the PHP set_include_path() | | | | Text_Highlighter::factory("Python"); |
| function as so: | | | | $hiPython->setRenderer($renderer); |
| <?php | | | | $hiRuby =& Text_Highlighter::factory("Ruby"); |
| $path = "{path/to/PEAR}"; | | | | $hiRuby->setRenderer($renderer); |
| $set = set_include_path(get_include_path() . | | | | $hiSql =& Text_Highlighter::factory("SQL"); |
| PATH_SEPARATOR . $path); | | | | $hiSql->setRenderer($renderer); |
| ?> | | | | $hiVbScript =& |
| 2) Then I set a require_once() function to the Text | | | | Text_Highlighter::factory("VBSCRIPT"); |
| Highlighter file. I placed the following code right after | | | | $hiVbScript->setRenderer($renderer); |
| my body tags: | | | | $hiXml =& Text_Highlighter::factory("XML"); |
| <?phprequire_once "Text | | | | $hiXml->setRenderer($renderer); |
| Highlighter.php";require_once "Text/Highlighter | | | | ?> |
| Renderer/Html.php"; | | | | To implement the highlighting in your code all you |
| $renderer = new | | | | need to do is: |
| Text_Highlighter_Renderer_Html(array("numbers" | | | | <?phpecho $hiHtml->highlight("<p>This is a |
| => HL_NUMBERS_LI, "tabsize" => 4)); | | | | sample of displaying and preformatting HTML code to |
| ?> | | | | display properly and that validates under W3C |
| The $render object set by | | | | standards.</p> |
| Text_Highlighter_Renderer_Html() sets numbers for | | | | <div>This is a div tag. I've used the character |
| each line of code and the othe r option sets the tabs | | | | entities for the HTML P tage and in the DIV tag< |
| for easier reading. I haven't quite figured out how the | | | | div> |
| tab works though. When I figure this out I'll post the | | | | <div>In this div tag I've used the numbered |
| solution. Right after the above code I set all the | | | | entities for the less than and greater than signs. |
| variables for each specific programming language as | | | | Though you can't see it displayed in the browser you |
| so: | | | | can check in the source code of the browser.< |
| <?php | | | | div>") |
| $hiHtml =& Text_Highlighter::factory("HTML"); | | | | ? |