preg_replace_callback(), how to pass function argument/param?

This is a discussion on preg_replace_callback(), how to pass function argument/param? within the PHP General forums, part of the PHP Programming Forums category; Hi, This is probably simple to answer for most of ya'll, but... preg_replace_callback($f, 'mah_processTags', $text); Besides the matches, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-30-2008
Micky Hulse
 
Posts: n/a
Default preg_replace_callback(), how to pass function argument/param?

Hi,

This is probably simple to answer for most of ya'll, but...

preg_replace_callback($f, 'mah_processTags', $text);

Besides the matches, how would I pass function args/param to
mah_processTags()?

For example, I would like to do something like this:

preg_replace_callback($f, 'mah_processTags($arg1)', $text);
function mah_processTags($matches, $arg1) { ... }

Is this even possible? I just want to pass-in $arg1 along with the
matches. :)

Possible?

Many thanks in advance!!!
Cheers,
Micky

--
Wishlist: <http://tinyurl.com/22xonb>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #2 (permalink)  
Old 03-30-2008
Casey
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(), how to pass function argument/param?

On Sun, Mar 30, 2008 at 1:17 AM, Micky Hulse <micky@ambiguism.com> wrote:
> Hi,
>
> This is probably simple to answer for most of ya'll, but...
>
> preg_replace_callback($f, 'mah_processTags', $text);
>
> Besides the matches, how would I pass function args/param to
> mah_processTags()?
>
> For example, I would like to do something like this:
>
> preg_replace_callback($f, 'mah_processTags($arg1)', $text);

preg_replace_callback($f, 'mah_processTags(\'$0\', $arg1)', $text);
Does this work?

> function mah_processTags($matches, $arg1) { ... }
>
> Is this even possible? I just want to pass-in $arg1 along with the
> matches. :)
>
> Possible?
>
> Many thanks in advance!!!
> Cheers,
> Micky
>
> --
> Wishlist: <http://tinyurl.com/22xonb>
> Switch: <http://browsehappy.com/>
> BCC?: <http://snipurl.com/w6f8>
> My: <http://del.icio.us/mhulse>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>




--
-Casey
Reply With Quote
  #3 (permalink)  
Old 03-30-2008
micky@ambiguism.com
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(),how to pass function argument/param?

Hi Casey! Many thanks for your help! I greatly appreciate it. :)

>> preg_replace_callback($f, 'mah_processTags($arg1)', $text);

> preg_replace_callback($f, 'mah_processTags(\'$0\', $arg1)', $text);
> Does this work?


Ah, interesting... Thanks for the example code... I am at work now, but
will try that as soon as I get home later tonight. Your code examp looks
very promising -- I will let you know how it goes.

A billion thanks!

Cheers,
Micky



Reply With Quote
  #4 (permalink)  
Old 03-31-2008
Micky Hulse
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(), how to pass function argument/param?

Casey wrote:
> preg_replace_callback($f, 'mah_processTags(\'$0\', $arg1)', $text);
> Does this work?


Awww, does not seem to work. :(

But maybe I need to dink with the code a bit more...

I would like to avoid setting a global here. :D

Thanks for the help Casey! I will let you know if I get it working. I
may just have to think of a different approach here.

Cheers,
Micky


--
Wishlist: <http://tinyurl.com/22xonb>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #5 (permalink)  
Old 03-31-2008
Casey
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(), how to pass function argument/param?

On Sun, Mar 30, 2008 at 9:37 PM, Micky Hulse <micky@ambiguism.com> wrote:
> Casey wrote:
> > preg_replace_callback($f, 'mah_processTags(\'$0\', $arg1)', $text);
> > Does this work?

>
> Awww, does not seem to work. :(
>
> But maybe I need to dink with the code a bit more...
>
> I would like to avoid setting a global here. :D
>
> Thanks for the help Casey! I will let you know if I get it working. I
> may just have to think of a different approach here.
>
>
>
> Cheers,
> Micky
>
>


Hmmm. I've searched around, and it seems that only a global would work :/

--
-Casey
Reply With Quote
  #6 (permalink)  
Old 03-31-2008
Micky Hulse
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(), how to pass function argument/param?

Casey wrote:
> Hmmm. I've searched around, and it seems that only a global would work :/


Thanks for the help Casey! I really appreciate it. :)

Yah, I think I will use a global for now... Until I can think of an
alternative coding approach.

Have a good one!

Cheers,
Micky


--
Wishlist: <http://tinyurl.com/22xonb>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #7 (permalink)  
Old 03-31-2008
Casey
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(), how to pass function argument/param?

On Sun, Mar 30, 2008 at 10:06 PM, Micky Hulse <micky@ambiguism.com> wrote:
> Casey wrote:
> > Hmmm. I've searched around, and it seems that only a global would work :/

>
> Thanks for the help Casey! I really appreciate it. :)
>
> Yah, I think I will use a global for now... Until I can think of an
> alternative coding approach.
>
> Have a good one!
>
>
>
> Cheers,
> Micky
>
>

What does mah_process_tags do anyway? XD

--
-Casey
Reply With Quote
  #8 (permalink)  
Old 03-31-2008
Micky Hulse
 
Posts: n/a
Default Re: [PHP] preg_replace_callback(), how to pass function argument/param?

Casey wrote:
> What does mah_process_tags do anyway? XD


Ah, hehe... Oh, basically I am trying to write a plugin for the
Textpattern CMS:

<http://textpattern.com/>

processTags() is a core TXP function... Basically, it parses any TXP
template tags (<txp:function_name atts="foo" />).

Long story short, I am am modifying the processTags() function so that
it looks for class methods when parsing template tags, vs. looking for
regular functions.

Thanks again Casey! I really appreciate your help. :)
Cheers,
Micky

--
Wishlist: <http://tinyurl.com/22xonb>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:56 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0