note 74969 added to function.preg-replace-callback
| From: | sjungwirthdomainmatrix-consultantscom at osu1 dot php dot net | Date: | Mon, 07 May 2007 00:31:38 +0000 |
| Subject: | note 74969 added to function.preg-replace-callback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126269@lists.php.net to get a copy of this message | ||
one way to 'pass' extra info other than just the matches and still use
preg_replace_callback is to have your callback function be a class method, and just before you call
preg_replace_callback, store the info in that class. I am using static methods/variables for my
implementation; I'm not sure if its required.
<?php
class foo {
private static $bar;
public static function do_something($bar) {
self::$bar = $bar; // store bar
$input = $bar->get_somevar();
$pattern = "match me";
$output = preg_replace_callback($pattern, array('self',
'do_something_callback'), $input);
return $output;
}
private static function do_something_callback($matches) {
$bar = self::$bar; // retrieve bar
// do stuff like $bar->get_someothervar();
return $replacement;
}
}
?>
----
Server IP: 69.39.81.135
Probable Submitter: 64.17.250.94
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php
Edit -- https://master.php.net/note/edit/74969
Del: integrated -- https://master.php.net/note/delete/74969/integrated
Del: useless -- https://master.php.net/note/delete/74969/useless
Del: bad code -- https://master.php.net/note/delete/74969/bad+code
Del: spam -- https://master.php.net/note/delete/74969/spam
Del: non-english -- https://master.php.net/note/delete/74969/non-english
Del: in docs -- https://master.php.net/note/delete/74969/in+docs
Del: other reasons-- https://master.php.net/note/delete/74969
Reject -- https://master.php.net/note/reject/74969
Search -- https://master.php.net/manage/user-notes.php