All pastes #388819 Raw Edit

Stuff

public php v1 · immutable
·published 2007-03-10 09:22 UTC
rendered paste body
<?php$text = 'Hello world. @/* this is a */comment followed by  some */ text';class Hilite {				function Comment($text) {			$open_tags = array('@', '#', '//');			$close_tags = array('@', '@');			$span_open = "<span style='color: red'>";			$span_close = "</span>";												$line = explode("\n", $text);			$numberOfLines = count($line);			$open = false;			for($i = 0; $i < $numberOfLines; $i++) {				// Need this for later				$comment_syntax_length = strlen($close_tags[$i]);									// Look for opening comment & closing comment				$bpos = strpos($line[$i], $open_tags[$i]);				// If it was found				if($bpos !== false) {							// Take everything to the left of it					$left = substr($line[$i], 0,  $bpos);					echo "$bpos -> $left <br>";					// Add span tag (opening)					$formatted_left = $left . $span_open;					// Add formatted left back to the original string					$line[$i] = str_replace($left, $formatted_left, $line[$i]);					// Search for the next */, starting from the location where /* was found					$epos = strpos($line[$i], $close_tags[$i], $bpos+1);						// if it was found					#if($epos !== false) {						$right = substr($line[$i], $epos + $comment_syntax_length);						echo "$epos -> $right";						$formatted_right = $span_close . $right;												$line[$i] = str_replace($right, $formatted_right, $line[$i]);						#}				}													#echo $line[$i];			} //#for loop								} //#cooment		}$h = new Hilite();$h->Comment($text);?>