note 44863 deleted from function.preg-replace-callback by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:44:36 +0000 |
| Subject: | note 44863 deleted from function.preg-replace-callback by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127651@lists.php.net to get a copy of this message | ||
Note Submitter:
----
if you want to send some extra parameters to your call back function here's how to do it (using
preg_replace instead!). i took the example from the manual, on how to convert html tags to upper
case...
if you don't use a class:
<?php
$extra_info = "some extra info";
echo preg_replace("/(<\/?)(\w+)([^>]*>)/e", "html_body('\\1',
'\\2', '\\3', '$extra_info')", $html_body);
function html_body($open_tag, $the_tag, $close_tag, $extra_info) {
return $before . strtoupper($middle) . $after;
}
?>
class example:
<?php
class SomeClass {
function SomeClass() {
$extra_info = "some extra info";
echo preg_replace("/(<\/?)(\w+)([^>]*>)/e",
"\\$this->html_body('\\1', '\\2', '\\3',
'$extra_info')", $html_body);
}
function html_body($open_tag, $the_tag, $close_tag, $extra_info) {
return $before . strtoupper($middle) . $after;
}
}
?>
now, if you'd like to pass an array :)
<?php
$extra_info = ("some extra info", "little more", "a bit more");
echo preg_replace("/(<\/?)(\w+)([^>]*>)/e", "html_body('\\1',
'\\2', '\\3', \\$extra_info)", $html_body);
function html_body($open_tag, $the_tag, $close_tag, $extra_info) {
return $before . strtoupper($middle) . $after;
}
?>
you can also pass the array as a reference...cool!
hope this helps someone! ;)