(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-18-24 02:33 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - preg_replace PHP question New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
DarkSlaya

930
Gamma Ray








Since: 11-17-05
From: Montreal, Canada

Last post: 6298 days
Last view: 6298 days
Posted on 05-11-06 08:47 PM Link | Quote
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.


(edited by DarkSlaya on 05-11-06 07:52 PM)
(edited by DarkSlaya on 05-11-06 07:54 PM)
(edited by DarkSlaya on 05-11-06 07:56 PM)
(edited by DarkSlaya on 05-11-06 07:59 PM)
(edited by DarkSlaya on 05-11-06 08:05 PM)
(edited by DarkSlaya on 05-11-06 08:06 PM)
interdpth

Mole
MZM rapist


 





Since: 11-18-05

Last post: 6298 days
Last view: 6298 days
Posted on 05-12-06 12:12 AM Link | Quote
I'm not good with PHP but what would taking out the '''s over the $1 do?
Black Lord +

Flurry


 





Since: 11-17-05
From: Where indians still roam...

Last post: 6299 days
Last view: 6300 days
Posted on 05-12-06 03:57 AM Link | Quote
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.
Boom.dk









Since: 11-18-05
From: Denmark

Last post: 6316 days
Last view: 6298 days
Skype
Posted on 05-12-06 04:23 AM Link | Quote
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.
DarkSlaya

930
Gamma Ray








Since: 11-17-05
From: Montreal, Canada

Last post: 6298 days
Last view: 6298 days
Posted on 05-12-06 08:36 AM Link | Quote
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)


(edited by DarkSlaya on 05-12-06 07:38 AM)
Boom.dk









Since: 11-18-05
From: Denmark

Last post: 6316 days
Last view: 6298 days
Skype
Posted on 05-12-06 07:05 PM Link | Quote
Originally posted by DarkSlaya
Actually, $1 and \\1 both work.


Oh? Well, you learn every day, don't you?
DtTvB the Yoshi

Red Paragoomba


 





Since: 12-02-05
From: Thailand

Last post: 6543 days
Last view: 6543 days
Posted on 05-13-06 05:22 AM Link | Quote
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.


(edited by DtTvB the Yoshi on 05-13-06 04:31 AM)
DarkSlaya

930
Gamma Ray








Since: 11-17-05
From: Montreal, Canada

Last post: 6298 days
Last view: 6298 days
Posted on 05-13-06 07:25 AM Link | Quote
Thanks. I actually forgot to put <?php and ?> in whatever I was trying to highlight.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - preg_replace PHP question |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.008 seconds; used 383.80 kB (max 470.32 kB)