【发布时间】:2011-11-16 11:40:22
【问题描述】:
字符串:
$string = '{$string#anything#something this string will output default |ucfirst|strtoupper}';
PREG_REPLACE_CALLBACK 代码(PHP):
$string = preg_replace_callback('/\{\$?([^# ]+)\#?([^ ]+)? ?([^|]+)?[ \|]?([^\}]+)?\}/', $matches, $string);
输出($matches):
Array
(
[0] => {$string#anything#something can you hear me? |ucfirst|ucfirst|ucfirst|strtoupper}
[1] => string
[2] => anything#something
[3] => can you hear me?
[4] => ucfirst|strtoupper
)
要求:代替{$string this string will output default |ucfirst|strtoupper},我想使用{$string this string will output default ucfirst|strtoupper}(注意:ucfirst前面的管道符号被删除);
重要提示:输出(即 $matches 数组)应该与上面打印的相同。
非常感谢您的帮助,感谢您的阅读。
【问题讨论】:
标签: php regex preg-replace-callback