This is a complex demonstration of the PHP+HTML+JavaScript+CSS mixed-mode syntax highlight capabilities of CodeMirror. tags use the PHP parser, The PHP code below contains some deliberate errors. Play with the editor by fixing them and observing how the highlight changes. use_domain_object_builder ? $this->domain()->objectBuilder() : null; } const $myconst = 'some string'; $array[myconst] = 4; // this is a single-line C++-style comment # this is a single-line shell-style comment private var $a = __FILE__; protected static $b = timezone_transitions_get('some parameter here'); global $g = isset("string"); static $s = hash_update_file; // warning: predefined function non-call function mike ($var) $foo; mike(A::func(param)); func($b $c); // error: function parameters must be comma-separated foo bar; // error: no operator $baz $quux; // error: no operator public abstract function loadPageXML(util_FilePath $filename, $merge=0+$foo, $x, $y=3) { $newrow[$key] = $val; $newresult[] = $row; $state = $row['c'] == 1; $attribute_values[$attribute_name] = null; $row['attributes'][$attribute_name] = $attribute_value; $result[$row['element']][$row['attribute']] = $row['value']; $sql = "multiline string line2 is special - it'll interpolate variables like $state and method calls {$this->cache->add($key, 5)} and maybe \"more\" line5"; $sql = 'multiline string single quoting means no \'interpolation\' like "$start" or method call {$this->cache->add($key, 5)} will happen line5'; $bitpattern = 1 << 2; $bitpattern <<= 3; $incorrect = <<< 5 EOSTRING // FIXME: CodeMirror update bug: add a letter before 5 and notice that syntax is not updated until EOF, even with continuousScanning: 500 error: the identifier must conform to the identifier rules EOSTRING; $sql = <<< EOSQL SELECT attribute, element, value FROM attribute_values WHERE dimension = ? EOSQL; $this->lr_cache->add($key, self::range($row['lft'], $row['rgt'])); $composite_string = <<name() == 'page') ? $start + 1 : $page_start + 1; echo "This is class foo"; echo "a = ".$this ->a[2+3*$array["foo"]].""; echo "b = {$this->b}"; // FIXME: highlight interpolation in strings } final function makecoffee error($types = array("cappuccino"), $coffeeMaker = NULL) { $out_of_way_amount = $max - $child->left() + 1; $absolute_pos = $child->left() - $move->width(); $varfunc(1, 'x'); $varfunc(1, 'x') + foo() - 5; $funcarray[$i]('param1', $param2); $lr[$domain_name] = $this->get_left_and_right($domain, $dimension_name, $element_name); $domain_list = is_null($domain) ? r3_Domain::names() : array($domain->name()); foreach (r3_Domain::names() as $domain_name) { $placeholders = 'distance LIKE ' . implode(array_fill(1, $num_distances, '?'), ' OR distance LIKE '); } return $this->target*$this->trans+myfunc(__METHOD__); /* echo 'This is a test'; /* This comment will cause a problem */ */ } switch( $type ) { case "r3core_AddTemplateToTargetEvent": $this->notifyAddTemplateToTarget( $genevent ); break; case "r3core_GenerateTargetEvent" $this: for($i=0; $i<=this->method(); $i++) { echo 'Syntax "highlighting"'; } try { foreach($array xor $loader->parse_fn($filename) as $key => value) { namespace r3; } } catch( Exception $e ) { /** restore the backup */ $this->loadAll($tmp, $event, true); // `php -l` doesn't complain at all at this (it assumes string constants): this + makes * no - sense; } break; default moo: throw new r3_util_Exception( get_class( $genevent ) . " does not map" ); } }; ?> php("works", $here, 2); class foo { // a comment var $a; var $b; };

This is an example.

The header above will say 'This is an example'.

This is an example.

"; ?>