preg_replace_callback // Type 2: Static class method call
kérdés a printFind callback függvényben/metódusban elérhető-e vhogy az eredeti a hívó objektum ill objattrib (esetünkben a $this->origText), vagy marad az eval-os megoldás ?kössz a választ
■ - <?php
- $sampleText = 'aaa 123 bbb';
- class fooFind{
- function fooFind($text){
- $this->origText = $text;
- preg_replace_callback('/[\d]+/',array('fooFind','printFind'),$this->origText);
- }
- function printFind($matchedText){
- echo 'Eredeti:'.$this->origText."\n";
- echo 'Találat:'.$matchedText[0]."\n";
- }
- }
- $myFoo = new fooFind($sampleText);
- ?>
- <?php
- $sampleText = 'aaa 123 bbb';
- class fooFind{
- function fooFind($text){
- $this->origText = $text;
- preg_replace('/[\d]+/e','$this->printFind(\'\\0\')',$this->origText);
- }
- function printFind($matchedText){
- echo 'Eredeti:'.$this->origText."\n";
- echo 'Találat:'.$matchedText."\n";
- }
- }
- $myFoo = new fooFind($sampleText);
- ?>
objektum
a preg_replace_callback()-nek inkább add meg az
array($this, 'printFind')
függvényt/metódust.köszi