1--TEST-- 2msgfmt_get/set_pattern() 3--EXTENSIONS-- 4intl 5--FILE-- 6<?php 7 8/* 9 * Get/set pattern. 10 */ 11 12 13function ut_main() 14{ 15 $res_str = ''; 16 $fmt = ut_msgfmt_create( "en_US", "{0,number} monkeys on {1,number} trees" ); 17 18 // Get default patten. 19 $res_str .= "Default pattern: '" . ut_msgfmt_get_pattern( $fmt ) . "'\n"; 20 $res_str .= "Formatting result: " . ut_msgfmt_format( $fmt, array(123, 456) ) . "\n"; 21 22 // Set a new pattern. 23 $pattern = "{0,number} trees hosting {1,number} monkeys"; 24 $res = ut_msgfmt_set_pattern( $fmt, $pattern ); 25 if( $res === false ) 26 $res_str .= ut_msgfmt_get_error_message( $fmt ) . " (" . ut_msgfmt_get_error_code( $fmt ) . ")\n"; 27 28 // Check if the pattern has been changed. 29 $res = ut_msgfmt_get_pattern( $fmt ); 30 if( $res === false ) 31 $res_str .= ut_msgfmt_get_error_message( $fmt ) . " (" . ut_msgfmt_get_error_code( $fmt ) . ")\n"; 32 $res_str .= "New pattern: '" . ut_msgfmt_get_pattern( $fmt ) . "'\n"; 33 $res_str .= "Formatted message: " . ut_msgfmt_format( $fmt, array(123, 456) ) . "\n"; 34 35 ut_msgfmt_set_pattern($fmt, str_repeat($pattern, 10)); 36 $res_str .= "New pattern: '" . ut_msgfmt_get_pattern( $fmt ) . "'\n"; 37 $res_str .= "Formatted message: " . ut_msgfmt_format( $fmt, array(123, 456) ) . "\n"; 38 $res = ut_msgfmt_set_pattern($fmt, "{0,number} trees hosting {1,number monkeys"); 39 if ($res !== false) die("ut_msgfmt_set_pattern should fail"); 40 $res_str .= ut_msgfmt_get_error_message( $fmt ) . " (" . ut_msgfmt_get_error_code( $fmt ) . ")\n"; 41 42 43 return $res_str; 44} 45 46include_once( 'ut_common.inc' ); 47ut_run(); 48 49?> 50--EXPECT-- 51Default pattern: '{0,number} monkeys on {1,number} trees' 52Formatting result: 123 monkeys on 456 trees 53New pattern: '{0,number} trees hosting {1,number} monkeys' 54Formatted message: 123 trees hosting 456 monkeys 55New pattern: '{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys{0,number} trees hosting {1,number} monkeys' 56Formatted message: 123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys123 trees hosting 456 monkeys 57Error setting symbol value at line 0, offset 26: U_PATTERN_SYNTAX_ERROR (65799) 58