home resources search newsjoinmembers: 6958
PHP Flash Java Ruby Windows Linux
Hiveminds | Sat, 2005-04-23 11:55  tags:

The codefilter module is in charge of control if and how server-side code or browser code is presented. The PHP version used must be taken in account as this module uses PHPs highlight_string() function. The hightlight_string()function is different on PHP5. PHP4 still uses font tags and other non XHTML compliant code. PHP5 uses the span tag and other XHTML compliant code.

printer-friendly version

Hiveminds's picture
This article brought to you by the Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously
Thoughtbox - So what did you think?



Hiveminds posted on: Sat, 2005-04-23 17:04.

When showing PHP code using the code tag in Drupal 4.5.2 the PHP code is not hightlighted as it is when a the <?php ?> tags are detected. This showing PHP code embedded in HTML difficult as there is no highlighting the readablility of the code is lost. Using the default PHP tag functionality causes the PHP code to be seperated out from the HTML and again losses readability.

Answer:

The following code can be changed in the codefilter.module so that the proper highlighting occurs. This code has been test on PHP5 only and the use of the code tag (code tags are replaced by a styled div) as a container has been removed. Giving the codefilter.module this functionality removes the need for using the php language tags to turn on hightlighting.

The new function code:


<?php
function codefilter_process_code($text) {
  
// Note, pay attention to odd preg_replace-with-/e behaviour on slashes
  
$text trim(str_replace('"''"'$text));
  
$text preg_replace('@</?(br|p)s*/?>@'''$text);
  
$text strtr($textarray_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  
$text highlight_string($text1);
  
$text '<div class="codeblock">'$text .'</div>';
  return 
$text;
}
?>

Output example:


<p>a html string </p><?php
   
print 'hellookworld';
?>
<p> a html string </p>
<p> a html string </p>
<?php
 
function me(){
   print 
'hellookworld';
}
?>
<p> a html string </p><?php print 'hello cool world';?><p> a html string </p>
<form action="<?php print $var;?>"></form>

 
 
Windows Drupal Silverlight Silverlight Adobe Flex Web Developers Web Developers
 videos
 articles
 blogs
 comments
 downloads
sitemap

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.

page top