php-src/ext/pcre/tests/007.phpt

84 lines
1.1 KiB
Plaintext
Raw Normal View History

2008-03-08 11:51:03 +00:00
--TEST--
preg_replace_callback() with callback that modifies subject string
--SKIPIF--
<?php
if (@preg_match('/./u', '') === false) {
die('skip no utf8 support in PCRE library');
}
?>
--FILE--
<?php
function evil($x) {
global $txt;
$txt[3] = "\xFF";
var_dump($x);
return $x[0];
}
$txt = "ola123";
var_dump(preg_replace_callback('#.#u', 'evil', $txt));
var_dump($txt);
var_dump(preg_last_error() == PREG_NO_ERROR);
var_dump(preg_replace_callback('#.#u', 'evil', $txt));
var_dump(preg_last_error() == PREG_BAD_UTF8_ERROR);
echo "Done!\n";
?>
2009-07-26 18:16:39 +00:00
--EXPECTF--
2008-03-08 11:51:03 +00:00
array(1) {
[0]=>
2009-07-26 18:16:39 +00:00
unicode(1) "o"
2008-03-08 11:51:03 +00:00
}
array(1) {
[0]=>
2009-07-26 18:16:39 +00:00
unicode(1) "l"
2008-03-08 11:51:03 +00:00
}
array(1) {
[0]=>
2009-07-26 18:16:39 +00:00
unicode(1) "a"
2008-03-08 11:51:03 +00:00
}
array(1) {
[0]=>
2009-07-26 18:16:39 +00:00
unicode(1) "1"
2008-03-08 11:51:03 +00:00
}
array(1) {
[0]=>
2009-07-26 18:16:39 +00:00
unicode(1) "2"
2008-03-08 11:51:03 +00:00
}
array(1) {
[0]=>
2009-07-26 18:16:39 +00:00
unicode(1) "3"
2008-03-08 11:51:03 +00:00
}
2009-07-26 18:16:39 +00:00
unicode(6) "ola123"
unicode(6) "ola%r\x{ff}%r23"
2008-03-08 11:51:03 +00:00
bool(true)
2009-07-26 18:16:39 +00:00
array(1) {
[0]=>
unicode(1) "o"
}
array(1) {
[0]=>
unicode(1) "l"
}
array(1) {
[0]=>
unicode(1) "a"
}
array(1) {
[0]=>
unicode(1) "%r\x{ff}%r"
}
array(1) {
[0]=>
unicode(1) "2"
}
array(1) {
[0]=>
unicode(1) "3"
}
unicode(6) "ola%r\x{ff}%r23"
bool(false)
2008-03-08 11:51:03 +00:00
Done!