PHP » PYTHON |
login |
register |
about
|
PYTHON preg_replace_callback
is this article helpful?
|
Python replacement for PHP's preg_replace_callback
[
edit
| history
]
import re result = re.sub(pattern, callback, subject) result = re.sub(pattern, callback, subject, limit) preg_replace_callback(PHP 4 >= 4.0.5, PHP 5) preg_replace_callback — Perform a regular expression search and replace using a callback Description
mixed preg_replace_callback
( mixed $pattern
, callback $callback
, mixed $subject
[, int $limit= -1
[, int &$count
]] )
The behavior of this function is almost identical to preg_replace(), except for the fact that instead of replacement parameter, one should specify a callback . Parameters
Return Valuespreg_replace_callback() returns an array if the subject parameter is an array, or a string otherwise. If matches are found, the new subject will be returned, otherwise subject will be returned unchanged. Changelog
Examples
Example #2 preg_replace_callback() example
<?php The above example will output: April fools day is 04/01/2003 Last christmas was 12/24/2002
Example #3 preg_replace_callback() using recursive structure to handle encapsulated BB code
<?php
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|