killah Posted April 12, 2009 Share Posted April 12, 2009 This has been getting to be for quite some time now. anyway this is what i have: '<span style="font-size: 11px;">Code:</span><br /> <div style="border: 1px black solid; background: #CCC; width: 99%; max-height: 24em; display: block; white-space: nowrap; overflow: auto; line-height: 1.3em; overflow: auto;">'.highlight_string(stripslashes('$1'), TRUE).'</div>', & '~\[code\](.*?)\[\/code\]~is', How ever, it just does not format it to highlight it. This is the output: Code: <?php echo 'Please work?'; ?> and from the <?php it just prints black. This is what i use to also get it to highlight.. <?php echo 'Please work?'; ?> and it seems like it just does not want to work. Can anyone help with this? Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/ Share on other sites More sharing options...
thebadbad Posted April 12, 2009 Share Posted April 12, 2009 Would be so much easier if you showed us the complete script. I'm guessing you're looking for something like this: <?php echo preg_replace('~\[code\](.*?)\[/code\]~ise', "'<span style=\"font-size: 11px;\">Code:</span><br /> <div style=\"border: 1px black solid; background: #CCC; width: 99%; max-height: 24em; display: block; white-space: nowrap; overflow: auto; line-height: 1.3em; overflow: auto;\">'.highlight_string(stripslashes('$1'), TRUE).'</div>'", $str); ?> Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-807881 Share on other sites More sharing options...
killah Posted April 12, 2009 Author Share Posted April 12, 2009 Unfortunatly, your code will not work. All you did was add echo and put the pattern and replace inside the preg_replace. Yet you still done it wrong. No i never tested as i can see clearly you done it incorrectly. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-807955 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 thebadbad's code does what you asked. It highlights the stuff between the code tags, wrapped in the styling you want. If you had bothered to try it out, you would have seen that it does work. the main thing to note is that he added the e modifier to the pattern so that the replacement will actually evaluate and execute the syntax highlighting. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-807991 Share on other sites More sharing options...
Daniel0 Posted April 12, 2009 Share Posted April 12, 2009 Owned. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-808003 Share on other sites More sharing options...
premiso Posted April 12, 2009 Share Posted April 12, 2009 Owned. Pwned would be a more accurate term. (If that even is a term ??? ) Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-808005 Share on other sites More sharing options...
bloodgoat Posted April 12, 2009 Share Posted April 12, 2009 I would say OP was thoroughly sonned. Good show. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-808008 Share on other sites More sharing options...
thebadbad Posted April 12, 2009 Share Posted April 12, 2009 You're welcome killah. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-808029 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 "You got F'd in the A" is the term South Park uses I believe. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-808032 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 Alright. The moral of the story here is that when you come to a forum to ask a question, don't be so hasty to disregard solutions given, as you clearly aren't in the know, yourself (otherwise you wouldn't be asking the question in the first place). And it's definitely not a good idea to be an ass about disregarding it, because karma is a bitch. I'm closing this thread before it gets ugly. Link to comment https://forums.phpfreaks.com/topic/153729-help-with-highlight_string/#findComment-808035 Share on other sites More sharing options...
Recommended Posts