Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
0 users currently in Programming. |
User | Post | ||||||||||||
DarkSlaya Posts: 592/936 |
Thanks. I actually forgot to put <?php and ?> in whatever I was trying to highlight. | ||||||||||||
DtTvB the Yoshi Posts: 55/60 |
My best way I found:
<?php
function bbc_hilight_it($matches) { return highlight_string($matches[1], 1); } function dosostuff($arg) { return preg_replace_callback('~\[tag\](.+?)\[\/tag\]~si', 'bbc_hilight_it', $arg); } ?> Notes on highlight_string - it has 2 parameters. First one is the string and it won't hilight if the code does not surrounded by And if the second parameter is zero or false, it will print out the string, else it will return the hilighted string, so better specify 1 to the string. Boom.dk |
Posts: 172/356 Originally posted by DarkSlaya Oh? Well, you learn every day, don't you? DarkSlaya |
Posts: 587/936 Actually, $1 and \\1 both work.
| As for my first problem, I used the preg_replace_callback() function. Which worked. Actually got hightlight_string() to work, but for some reason it changes the font only to black. (probably my server) Boom.dk |
Posts: 171/356 You should prolly do like this:
| $arg = preg_replace("@\[tag\](.*?)\[/tag\]@si", highlight_string("\\1"), $arg); I've used @ instead of ' for no specific reason, I just like it better. Anyways, the stuff in (.*?) will become \\1 not $1. Black Lord + |
Posts: 110/273 What is it, exactly, that you are trying to do..., from what I'm guessing you want to highlight the syntax of whatever is in variable $1 and then after you highlight it, you want to replace any [tag][/tag] brackets in the $arg variable with whatever is returned from the highlight_string().... assuming you have the second parameter of the highlight string set to true... if that's the case, I want to know what the hell is you're idea behind doing this, like, what exactly it is you want to do. | interdpth |
Posts: 150/362 I'm not good with PHP but what would taking out the '''s over the $1 do? | DarkSlaya |
Posts: 586/936 So I've got a function:
| function dosostuff($arg) { $arg = preg_replace("'\[tag\](.*?)\[/tag\]'si", highlight_string('$1'), $arg); return $arg; } Now, highlight_string (in exemple, any other functions, like my own), doesn't do anything. How do I make it work (or any functions, in the preg_replace). EDIT: Ah. I'm retarded. I just read that hightlight_string doesn't return a string. And I forgot to put the return $stuff; in my other function. BUt still, so this thread isn't useless. How do I use hightlight_string in the preg_replace. EDIT 2: Nevermind, still doesn't change my stuff. The other function I call (if you haven't noticed) also change stuff. EDIT 3: It seems like the $1 is sent to the other function, not the actually value. |