1.11M Members

help with preg_replace_callback function

 
0
 

hi there, this is my class that uses preg_replace_callback
I know that when this function used in class
i do like that
**preg_replace_callback('|(\d{2}/\d{2}/)(\d{4})|',array(&$this, 'next_year'), $text); **

but i dont understand & in front of $this statement
if i dont write the & reference operator in front of this it also works. what does it mean?
can anyone help to understand? thanks in advance

class az {

// the callback function
function __construct($text){

    $this->ParseText($text);
}
function next_year($matches)
{
  // as usual: $matches[0] is the complete match
  // $matches[1] the match for the first subpattern
  // enclosed in '(...)' and so on
  return $matches[1].($matches[2]+1);
}


  function ParseText($text)
  {
    return preg_replace_callback('|(\d{2}/\d{2}/)(\d{4})|',array(&$this, 'next_year'), $text); 
  }

}
class mm {

    function yaz($text){

        $n=new az($text);

    }




}
$text = "April fools day is 04/01/2002\n";
$text.= "Last christmas was 12/24/2001\n";
$azs=new mm($text);
 
0
 

The & referencing is something that predates PHP5 and it's use is now no longer needed.

Question Answered as of 6 Months Ago by pritaeas
 
0
 

Thank you very much!

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article