SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old May 9th, 2002, 07:32 PM
everytime everytime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: *.*
Posts: 133 everytime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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.

Reply With Quote
  #2  
Old May 9th, 2002, 07:32 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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?

Reply With Quote
  #3  
Old May 13th, 2002, 10:34 AM
everytime everytime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: *.*
Posts: 133 everytime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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!).

Reply With Quote
  #4  
Old May 13th, 2002, 02:53 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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...

Reply With Quote
  #5  
Old May 15th, 2002, 05:17 PM
everytime everytime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: *.*
Posts: 133 everytime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > colored code pt2


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway