source: branches/version-2_5-dev/data/module/Compat/tests/function/str_ireplace.phpt @ 19792

Revision 19792, 2.7 KB checked in by Seasoft, 13 years ago (diff)

#744(PHP4 互換用途ソースを将来的に切り捨てやすい仕組みづくり)

Line 
1--TEST--
2Function -- str_ireplace
3--SKIPIF--
4<?php if (function_exists('str_ireplace')) { echo 'skip'; } ?>
5--FILE--
6<?php
7require_once 'PHP/Compat.php';
8PHP_Compat::loadFunction('str_ireplace');
9
10//
11// Simple
12//
13
14$search = '{object}';
15$replace = 'fence';
16$subject = 'The dog jumped over the {object}';
17
18echo str_ireplace($search, $replace, $subject), "\n";
19
20//
21// Test 1: With subject as array
22//
23
24// As a full array
25$search = '{SUBJECT}';
26$replace = 'Lady';
27$subject = array('A {subject}', 'The {subject}', 'My {subject}');
28print_r(str_ireplace($search, $replace, $subject));
29
30// As a single array
31$search = '{SUBJECT}';
32$replace = 'Lady';
33$subject = array('The dog jumped over the {object}');
34print_r(str_ireplace($search, $replace, $subject));
35
36
37//
38// Test 2: Search as string, replace as array
39//
40
41$search = '{object}';
42$replace = array('cat', 'dog', 'tiger');
43$subject = 'The dog jumped over the {object}';
44// Supress the error, no way of knowing how it'll turn out on the users machine
45echo @str_ireplace($search, $replace, $subject), "\n";
46
47
48//
49// Test 3: Search as array, Replace as string
50//
51
52$search = array('{ANIMAL}', '{OBJECT}', '{THING}');
53$replace = 'frog';
54$subject = 'The {animal} jumped over the {object} and the {thing}...';
55echo str_ireplace($search, $replace, $subject), "\n";
56
57
58//
59// Test 4: Search and Replace as arrays
60//
61
62// Simple
63$search = array('{ANIMAL}', '{OBJECT}');
64$replace = array('frog', 'gate');
65$subject = 'The {animal} jumped over the {object}';
66echo str_ireplace($search, $replace, $subject), "\n";
67
68// More in search
69$search = array('{ANIMAL}', '{OBJECT}', '{THING}');
70$replace = array('frog', 'gate');
71$subject = 'The {animal} jumped over the {object} and the {thing}...';
72echo str_ireplace($search, $replace, $subject), "\n";
73
74// More in replace
75$search = array('{ANIMAL}', '{OBJECT}');
76$replace = array('frog', 'gate', 'door');
77$subject = 'The {animal} jumped over the {object} and the {thing}...';
78echo str_ireplace($search, $replace, $subject), "\n";
79
80
81//
82// Test 5: All arrays
83//
84
85$search = array('{ANIMAL}', '{OBJECT}', '{THING}');
86$replace = array('frog', 'gate', 'beer');
87$subject = array('A {animal}', 'The {object}', 'My {thing}');
88print_r(str_ireplace($search, $replace, $subject));
89
90?>
91--EXPECT--
92The dog jumped over the fence
93Array
94(
95    [0] => A Lady
96    [1] => The Lady
97    [2] => My Lady
98)
99Array
100(
101    [0] => The dog jumped over the {object}
102)
103The dog jumped over the Array
104The frog jumped over the frog and the frog...
105The frog jumped over the gate
106The frog jumped over the gate and the ...
107The frog jumped over the gate and the {thing}...
108Array
109(
110    [0] => A frog
111    [1] => The gate
112    [2] => My beer
113)
Note: See TracBrowser for help on using the repository browser.