473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

preg_replace_callback, how to use in object ?

this is my problem:

Class myClass {

function process($matches) {return something($matches);}

function myReplace($input)
{
return preg_replace_callback(/pattern/, '$this->process', $input)
}
}

problem is '$this->process' isn't a valid callback.

How can I do this?
Jun 2 '08 #1
2 3548
On Apr 14, 9:34 am, Snaggy <l.cio...@gmail.comwrote:
this is my problem:

Class myClass {

function process($matches) {return something($matches);}

function myReplace($input)
{
return preg_replace_callback(/pattern/, '$this->process', $input)

}
}

problem is '$this->process' isn't a valid callback.
No, but this is:

array($this, 'process')
Jun 2 '08 #2
On 14 avr, 15:34, Snaggy <l.cio...@gmail.comwrote:
this is my problem:

Class myClass {

function process($matches) {return something($matches);}

function myReplace($input)
{
return preg_replace_callback(/pattern/, '$this->process', $input)

}
}

problem is '$this->process' isn't a valid callback.

How can I do this?
Hi,

You can do this :

preg_replace_callback( /pattern/, array($this, 'process'), $input);

Ci@
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian.H | last post by:
Hi all, I'm trying to write a PHP colour parser and after various attempts, something, somewhere trips it over. Some details: String to parse: $origString = '^1foo^5bar';
1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
0
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What...
8
by: jody.florian | last post by:
Hi, I'm trying to use preg_replace_callback within a method. The preg_replace_callback() & mycallback() pair will only be used by this method, and this method will probably only be called once...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
14
by: mens libertina | last post by:
Disclaimer: In addition to reading the skimpy entries at php.net, I've searched this group and alt.php to no avail. Basically, I'm trying to use a template to send email reminders, but I can't...
2
by: Kimmo Laine | last post by:
I tried to use a class member function as a callback in preg_replace_callback, but failed. It announces: " Warning: preg_replace_callback() : requires argument 2, 'myclass::myfunction', to be a...
0
by: Stephen Kay | last post by:
I'm having a problem where I changed hosts, went from php 4.1.2 to php 4.4.4, and now preg_replace_callback() is segfaulting when I pass it html that is longer than 2732 bytes. This code has worked...
4
by: Jeff | last post by:
I've been struggling with this for a while. Here's what I'm trying to do: private function makeMiniTemplate($ARRAY){ /* $ARRAY looks like this: $ARRAY='Some Value';
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.