Forums
This topic is locked
preg_replace_callback
Posted 18 Dec 2001 11:05:50
1
has voted
18 Dec 2001 11:05:50 Bruno Mairlot posted:
Hi All,The function <b>preg_replace_callback</b> performs a replacement functionnality by calling a callback.
The callback may be the name of a function. If you just use it that way it works fine.
<pre id=code><font face=courier size=2 id=code>
preg_replace_callback("/\@\@(\w+)\@\@/",'callb',$contents);
</font id=code></pre id=code>
But in the above code I just tell him to use the 'callb' function. How do I specify other arguments to 'callb' that I want it to use ?
Thanks
Bruno
--- Better to die trying, than never try at all ---
Replies
Replied 18 Dec 2001 12:31:38
18 Dec 2001 12:31:38 Tim Green replied:
The easiest way to do this Bruno is going to be by defining a global variable prior to the ereg_replace_callback call.
There are ways to actually do this using an array containing the function name and other information instead of putting just the function name in the call, but it is apparently difficult to retrieve the returned RegExp object.
To save on development time etc it is going to be easier in the long run to set up a global variable containing the info you need before the preg_replace_callback call. Not the best solution I know, but about the best I can think of.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
There are ways to actually do this using an array containing the function name and other information instead of putting just the function name in the call, but it is apparently difficult to retrieve the returned RegExp object.
To save on development time etc it is going to be easier in the long run to set up a global variable containing the info you need before the preg_replace_callback call. Not the best solution I know, but about the best I can think of.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 19 Dec 2001 10:45:37
19 Dec 2001 10:45:37 Bruno Mairlot replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
There are ways to actually do this using an array containing the function name and other information instead of putting just the function name in the call, but it is apparently difficult to retrieve the returned RegExp object.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Well after many many tries, it appears that the only way to use the array in the callback parameter, is when you're using a Object, and then set the object's method you want to use.
Otherwise, PHP will complain that the array is not a correct callback.
Therefore, the solution I found, is that, instead of using global variable, which in this case would have been very nasty, I set the object properties, so that the callback function knows about which variables to use and how to use them.
Thank you Tim <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
--- Better to die trying, than never try at all ---
There are ways to actually do this using an array containing the function name and other information instead of putting just the function name in the call, but it is apparently difficult to retrieve the returned RegExp object.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Well after many many tries, it appears that the only way to use the array in the callback parameter, is when you're using a Object, and then set the object's method you want to use.
Otherwise, PHP will complain that the array is not a correct callback.
Therefore, the solution I found, is that, instead of using global variable, which in this case would have been very nasty, I set the object properties, so that the callback function knows about which variables to use and how to use them.
Thank you Tim <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
--- Better to die trying, than never try at all ---