News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

phphighlight question

Started by Aquilo, December 14, 2003, 11:52:18 PM

Previous topic - Next topic

Aquilo

ok I have looked and only found the dead links to what I think is in Yabb SE right now and I have tryed and tryed to get phphighlight() to work, I'm using PHP 4.3.3 so this should work. the closest I've come actualy makes the forum get parsed and return wacky code, and way any one know how to get phphighlight() to work proprely in YaBB SE 1.5.4? I have no more hair to pull!  :D

thanks!!!

[Unknown]

I wrote a mod, err... somewhere, to do PHP highlighting.  It's on yabbse.org somewhere.  I think in "Mod Ideas".

-[Unknown]

Aquilo

 ;D thanks the search still didn't find it but listing all 7000+ (well only 5866 got listed) of your got it num 736! :D

but it's busted!
http://www.yabbse.org/community/index.php?thread=25218/0

in this worked for you once I'll see why it messing with image tages!

[Unknown]

It shouldn't break img, are you sure it does?

-[Unknown]

Aquilo

#4
sorry it was breaking url tages.

I have it working but only with code tages so I need to work out a way to also do [ php ] tages
just for php.

I used an elseif in your mod for picking out the code part but some thing else was not letting the [ url ] tags work.

please note that this is what I have so far but the tables are edited and removed in phphighlight so this is not pasting code!!
function doUBBC($message,$enableSmilies = 1)
{
//echo $message;
global $settings, $text, $txt;

$parts = split('\[\/?code\]', ' ' . $message);

for ($i = 0; $i < count($parts); $i++)
{
if ($i % 2 == 0)
{
$parts[$i] = str_replace(array('$', '[[', ']]'), array('&#36;', '{<{', '}>}'), $parts[$i]);
if ($i > 0)
$parts[$i] = '</font></td></tr></table>' . $parts[$i];
$parts[$i] = preg_replace("/([\n >\(])([\w\-_]+?):\/\/([\w\-_@:]+)((\.[\w\-_]+)+(:[\d]+)?((\/[\w\-_%]+(\.[\w\-_%]+)*)|(\/[~]?[\w\-_%]*))*(\/?(\?[&;=\w\+%]+)*)?(#[\w\-_]*)?)/", "\\1[url=http://\\2://\\3\\4]\\2://\\3\\4[/url]", $parts[$i]);
$parts[$i] = preg_replace("/([\n >\(])www((\.[\w\-_]+)+(:[\d]+)?((\/[\w\-_%]+(\.[\w\-_%]+)*)|(\/[~]?[\w\-_%]*))*(\/?(\?[&;=\w\+%]+)*)?(#[\w\-_]*)?)/", "\\1[url=http://www\\2]www\\2[/url]", $parts[$i]);
$parts[$i] = doparsecodesmilies($parts[$i], $enableSmilies);
}
elseif ($i < count($parts))
{
$parts[$i] = phphighlight($parts[$i]);
}
elseif ($i <= count($parts) - 1)
{
$parts[$i] = '<table border="0" cellspacing="1" cellpadding="2" width="100%"><caption align="left"><font size="1"><b>' . $txt['yse238'] . ':</b></font></caption><tr><td class="code"><font face="Courier new">' . $parts[$i];
}
}
$message = substr(implode('', $parts), 1);
unset($parts);

$message = str_replace(
array('{<{', '}>}', '  ', "\t", "\n\r", "\r", "\n"),
array('[', ']', '&nbsp; ', '&nbsp; &nbsp; ', '<br />', '<br />', '<br />'), $message);

return $message;
}




function phphighlight($code)
{
if (floor(phpversion()) < 4)
$buffer=$code;
else
{
$code = stripslashes($code);
$code = str_replace(array('&gt;', '&lt;', '&#36;', '&quot;'), array('>', '<', '$', '"'), $code);
$code = str_replace('<br />', "\n", $code);
$code = html_entity_decode($code, ENT_QUOTES);

if (!strstr($code, '<?'))
{
$code="<?php\n".trim($code)."\n?" .'>';
$addedtags = 1;
}

$buffer = highlight_string($code,1);
$buffer = stripslashes($buffer);
}
return '<table border="
0" cellspacing="1" cellpadding="2" width="100%"><tr><td>
<fieldset style="
padding: 2" class="code" ><legend>PHP CODE</legend><code>' . $buffer . '</code></fieldset>';
}


here is a link to this working
highlighted code

[Unknown]

Well, I totally rewrote it for SMF.  I'd give you the code, but... uhh... well, you'd need SMF too.

-[Unknown]

Aquilo

hehehe I got it going!!
thanks [Unknown]!
all working now

Advertisement: