Code View experiment
Last updated: April 28, 2007
Back to the JavaScript Experiments index.
Back to the Lab index.
pre > code
/* Example Listing */
$code = trim(file_get_contents('./highlight.php'));
ini_set('highlight.comment', 'comment');
ini_set('highlight.default', 'default');
ini_set('highlight.keyword', 'keyword');
ini_set('highlight.string', 'string');
ini_set('highlight.html', 'html');
$code = highlight_string($code, TRUE);
/* Clean Up */
$code = substr($code, 33, -16);
$code = str_replace(' ', ' ', $code);
$code = str_replace('<br />', "\n", $code);
$code = str_replace('<span style="color: ', '<span class="', $code);
/* Normalize Newlines */
$code = str_replace("\r", "\n", $code);
while (strpos($code, "\n\n\n") !== FALSE) {
$code = str_replace("\n\n\n", "\n\n", $code);
}
$lines = explode("\n", $code);
pre
(no child code
)
/* Example Listing */ $code = trim(file_get_contents('./highlight.php')); ini_set('highlight.comment', 'comment'); ini_set('highlight.default', 'default'); ini_set('highlight.keyword', 'keyword'); ini_set('highlight.string', 'string'); ini_set('highlight.html', 'html'); $code = highlight_string($code, TRUE); /* Clean Up */ $code = substr($code, 33, -16); $code = str_replace(' ', ' ', $code); $code = str_replace('<br />', "\n", $code); $code = str_replace('<span style="color: ', '<span class="', $code); /* Normalize Newlines */ $code = str_replace("\r", "\n", $code); while (strpos($code, "\n\n\n") !== FALSE) { $code = str_replace("\n\n\n", "\n\n", $code); } $lines = explode("\n", $code);
pre.code > code
/* Example Listing */
$code = trim(file_get_contents('./highlight.php'));
ini_set('highlight.comment', 'comment');
ini_set('highlight.default', 'default');
ini_set('highlight.keyword', 'keyword');
ini_set('highlight.string', 'string');
ini_set('highlight.html', 'html');
$code = highlight_string($code, TRUE);
/* Clean Up */
$code = substr($code, 33, -16);
$code = str_replace(' ', ' ', $code);
$code = str_replace('<br />', "\n", $code);
$code = str_replace('<span style="color: ', '<span class="', $code);
/* Normalize Newlines */
$code = str_replace("\r", "\n", $code);
while (strpos($code, "\n\n\n") !== FALSE) {
$code = str_replace("\n\n\n", "\n\n", $code);
}
$lines = explode("\n", $code);
pre.code
(no child code
)
/* Example Listing */ $code = trim(file_get_contents('./highlight.php')); ini_set('highlight.comment', 'comment'); ini_set('highlight.default', 'default'); ini_set('highlight.keyword', 'keyword'); ini_set('highlight.string', 'string'); ini_set('highlight.html', 'html'); $code = highlight_string($code, TRUE); /* Clean Up */ $code = substr($code, 33, -16); $code = str_replace(' ', ' ', $code); $code = str_replace('<br />', "\n", $code); $code = str_replace('<span style="color: ', '<span class="', $code); /* Normalize Newlines */ $code = str_replace("\r", "\n", $code); while (strpos($code, "\n\n\n") !== FALSE) { $code = str_replace("\n\n\n", "\n\n", $code); } $lines = explode("\n", $code);
pre > code
with blank lines
Blank lines should be ignored by the script when creating the ol
.
/* Example Listing */
$code = trim(file_get_contents('./highlight.php'));
ini_set('highlight.comment', 'comment');
ini_set('highlight.default', 'default');
ini_set('highlight.keyword', 'keyword');
ini_set('highlight.string', 'string');
ini_set('highlight.html', 'html');
$code = highlight_string($code, TRUE);
/* Clean Up */
$code = substr($code, 33, -16);
$code = str_replace(' ', ' ', $code);
$code = str_replace('<br />', "\n", $code);
$code = str_replace('<span style="color: ', '<span class="', $code);
/* Normalize Newlines */
$code = str_replace("\r", "\n", $code);
while (strpos($code, "\n\n\n") !== FALSE) {
$code = str_replace("\n\n\n", "\n\n", $code);
}
$lines = explode("\n", $code);
Test dynamically created pre.code
generate pre.code (cheating by using inline JavaScript)
Back to the Lab index.