How to retrieve method of a class in anonymous function? Does another opportunity exist to solve this?
Task: I need to upload a image from remote path and change it to local path.
Code:
$pattern = '/<img src=(.*?jpg|gif|png).*?>/m';
$uploadImage = function($image)
{
$this->uploadPictures();
};
function image_replace($matches) use ($uploadImage)
{
// как обычно: $matches[0] - полное вхождение шаблона
// $matches[1] - вхождение первой подмаски,
// заключенной в круглые скобки, и так далее...
$uploadImage($matches[1]);
return $matches[1].($matches[2]+1);
}
preg_replace_callback(
$pattern,
"image_replace",
$text);
$matchcontains.$thisis used out of the scope. Can you update how that class looks?