2
private function Photo($m,$photo){

  if($m == 'print'){
    print $photo; // or echo
  }
  else {
    return $photo;
  }
}

private function GetText(){
  ...
  ...
  $i = $res->fetch_assoc();
  $Text = $i["Text"];

    Now `$Text` have next:

     html text
     ....
     <p>%photo(2)%</p>
     <p>%photo(3)%</p>
     <p>%photo(4)%</p>
     ...
     html text

  echo $Text;
}

I would like replace text %photo(N)% (where N - it any number) on function Photo($m,N) (or function Photo(N)).

For this i use code:

$Text = preg_replace_callback("/\{photo\((\d+)\)\}/","Photo",$Text);

But it not work...

Tell me please how make it ?

P.S.: After replace $Text my example should been next:

html text
....
<p>2</p>
<p>3</p>
<p>4</p>
...
html text

1 Answer 1

1

Photo is a method of the class, not a function in itself.

Try:

$Text = preg_replace_callback("/\{photo\((\d+)\)\}/",array($this,"Photo"),$Text);

For more on the callable typehint, check the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.