1--TEST-- 2Test preg_replace() function : error - bad regular expressions 3--FILE-- 4<?php 5/* 6* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]]) 7* Function is implemented in ext/pcre/php_pcre.c 8*/ 9error_reporting(E_ALL&~E_NOTICE); 10/* 11* Testing how preg_replace reacts to being passed the wrong type of regex argument 12*/ 13echo "*** Testing preg_replace() : error conditions***\n"; 14$regex_array = array('abcdef', //Regex without delimiter 15'/[a-zA-Z]', //Regex without closing delimiter 16'[a-zA-Z]/', //Regex without opening delimiter 17'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes 18'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string 19); 20$replace = 1; 21$subject = 'a'; 22foreach($regex_array as $regex_value) { 23 print "\nArg value is $regex_value\n"; 24 var_dump(preg_replace($regex_value, $replace, $subject)); 25} 26$regex_value = new stdclass(); //Object 27try { 28 var_dump(preg_replace($regex_value, $replace, $subject)); 29} catch (Error $e) { 30 echo $e->getMessage(), "\n"; 31} 32?> 33--EXPECTF-- 34*** Testing preg_replace() : error conditions*** 35 36Arg value is abcdef 37 38Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in %spreg_replace_error1.php on line %d 39NULL 40 41Arg value is /[a-zA-Z] 42 43Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d 44NULL 45 46Arg value is [a-zA-Z]/ 47 48Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d 49NULL 50 51Arg value is /[a-zA-Z]/F 52 53Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d 54NULL 55 56Arg value is Array 57string(1) "a" 58 59Arg value is /[a-zA-Z]/ 60string(1) "1" 61Object of class stdClass could not be converted to string 62