xref: /PHP-5.6/Zend/tests/closure_008.phpt (revision bc12bc69)
1--TEST--
2Closure 008: Use in preg_replace_callback()
3--FILE--
4<?php
5
6function replace_spaces($text) {
7	$lambda = function ($matches) {
8		return str_replace(' ', '&nbsp;', $matches[1]).' ';
9	};
10	return preg_replace_callback('/( +) /', $lambda, $text);
11}
12
13echo replace_spaces("1 2 3\n");
14echo replace_spaces("1  2  3\n");
15echo replace_spaces("1   2   3\n");
16echo "Done\n";
17?>
18--EXPECT--
191 2 3
201&nbsp; 2&nbsp; 3
211&nbsp;&nbsp; 2&nbsp;&nbsp; 3
22Done
23