|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
colored code pt2
well I'm getting close to proper forum formatting but I'm stuck at this point.
On my php page I loop through the output of the database fine and I have a class (below) on the page to do the formatting. It uses ereg_replace but for some reason it isn't passing on the variable. Check out the code and it might become clear <?php class formatCode { function formatCode($text = "") { $text = "<?php $text ?>"; ob_start(); highlight_string($text); $text = ob_get_contents(); ob_end_clean(); return $text; } function formatThread($threadString) { $threadString = preg_replace("/[CODE1](.*?)[/CODE1]/si", $this->formatCode("1"), $threadString); #$threadString = "<span class='threadTitle'>" . $threadString . "</span>"; $threadString = nl2br($threadString); return $threadString; } } ?> The page calls formatThread function. Unfortunately only '1' is passed to the formatCode and not what ereg_replace should be finding. I need to pass the contents that are between the string pattern to the formatCode function. Any help is, as always, appreciated. |
|
#2
|
|||
|
|||
|
RE: colored code pt2
I'm confused because of the poor handling of backslashes in this forum (yes, I know I need to get into this code and fix it). Anyway, are you using:
\1 or juse 1 ? That is two backslashes 1 or one backslash 1? |
|
#3
|
|||
|
|||
|
RE: colored code pt2
Oh yeah! it is 2 backslahes. All that gets displayed through format code though is backslash and a one (written out here to avoid confusion!).
|
|
#4
|
|||
|
|||
|
RE: colored code pt2
Ok, well I don't claim to be an expert on regular expressions, but this example in the manual sheds a little light:
preg_replace ("/(</?)(w+)([^>]*>)/e", "'\1'.strtoupper('\2').'\3'", $html_body); that example would lead me to believe that you should be able to do this: $threadString = preg_replace("/[CODE1](.*?)[/CODE1]/si", "$this->formatCode('\1')", $threadString); Let me know how it goes... |
|
#5
|
|||
|
|||
|
RE: colored code pt2
Thanks for the suggestion Matt. Feels like I'm getting close...
Unfortunately it doesn't seem to pass anything to the formatCode function this way but at least there were no errors. If you, or anyone, can think of anything else let me know. I'll keep working on it and keep you posted. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > colored code pt2 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|