PHP How right replace text on function? -


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"];      `$text` have next:       html text      ....      <p>%photo(2)%</p>      <p>%photo(3)%</p>      <p>%photo(4)%</p>      ...      html text    echo $text; } 

i replace text %photo(n)% (where n - number) on function photo($m,n) (or function photo(n)).

for use code:

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

but not work...

tell me please how make ?

p.s.: after replace $text example should been next:

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

photo method of class, not function in itself.

try:

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

for more on callable typehint, check documentation.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -