rfc:preg_replace_callback_array
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:preg_replace_callback_array [2015/03/10 13:25] – created demon | rfc:preg_replace_callback_array [2015/03/10 13:54] – demon | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: Add preg_replace_callback_array function |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2015-03-10 | * Date: 2015-03-10 | ||
Line 7: | Line 7: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The preg_replace_callback_array function is an extension to preg_replace_callback. With the function, each pattern | + | Before 5.5.0, we can use the '/ |
- | + | <code php Zend/ | |
- | This is the best way to implement when there are multiple patterns. | + | $code = preg_replace( |
+ | array( | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | ), | ||
+ | array( | ||
+ | " | ||
+ | " | ||
+ | "' | ||
+ | "' | ||
+ | ), | ||
+ | $code); | ||
+ | </ | ||
- | ===== Proposal ===== | + | Since 5.5.0, we deprecated |
- | Below is the previous code, which is from Zend/ | + | <code php Zend/ |
- | + | ||
- | < | + | |
$code = preg_replace_callback( | $code = preg_replace_callback( | ||
array( | array( | ||
Line 34: | Line 46: | ||
}, $code); | }, $code); | ||
</ | </ | ||
+ | |||
+ | ===== Proposal ===== | ||
+ | The preg_replace_callback_array function is an extension to preg_replace_callback. With the function, each pattern can easily have a specific callback. | ||
+ | |||
+ | This is the best way to implement when there are multiple patterns. | ||
With preg_replace_callback_array, | With preg_replace_callback_array, | ||
- | <code php> | + | With the preg_replace_callback_array function, the code is: |
+ | < | ||
$code = preg_replace_callback_array( | $code = preg_replace_callback_array( | ||
array( | array( | ||
Line 55: | Line 73: | ||
</ | </ | ||
- | The first parameter is an array in this function. In this parameter, Key is parameter, and value is callback. Subject will iterate and match each key. If it is matched, the callback will be called. In the meanwhile, the result will be the new subject and passed to the next match. | + | The first parameter is an array in this function. In this parameter, Key is pattern, and value is callback. Subject will iterate and match each key. If it is matched, the callback will be called. In the meanwhile, the result will be the new subject and passed to the next match. |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | >= PHP 7.0.0 | + | This is proposed for PHP7 |
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== |
rfc/preg_replace_callback_array.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1