PHP Conference Kansai 2025

Voting

: min(four, seven)?
(Example: nine)

The Note You're Voting On

zer0
19 years ago
Concerning my code below:

I'm sorry, I completely forgot about str_ireplace being for PHP 5 for some reason. Also, there was another error I missed (too many late nights ;)). Here's the corrected code:

<?php
function highlight_code($code, $inline=false, $return=false) // Pre php 4 support for capturing highlight
{
(string)
$highlight = "";
if (
version_compare(PHP_VERSION, "4.2.0", "<") === 1 )
{
ob_start(); // start output buffering to capture contents of highlight
highlight_string($code);
$highlight = ob_get_contents(); // capture output
ob_end_clean(); // clear buffer cleanly
}
else
{
$highlight=highlight_string($code, true);
}

# Using preg_replace will allow PHP 4 in on the fun
if ( $inline === true )
$highlight=preg_replace("/<code>/i","<code class=\"inline\">",$highlight);
else
$highlight=preg_replace("/<code>/i","<code class=\"block\">",$highlight);

if (
$return === true )
{
return
$highlight;
}
else
{
echo
$highlight;
}
}
?>

<< Back to user notes page

To Top