summaryrefslogtreecommitdiff
path: root/ext/pcre/tests/preg_replace_callback_basic.phpt
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/pcre/tests/preg_replace_callback_basic.phpt
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/pcre/tests/preg_replace_callback_basic.phpt')
-rw-r--r--ext/pcre/tests/preg_replace_callback_basic.phpt33
1 files changed, 33 insertions, 0 deletions
diff --git a/ext/pcre/tests/preg_replace_callback_basic.phpt b/ext/pcre/tests/preg_replace_callback_basic.phpt
new file mode 100644
index 0000000..01d290a
--- /dev/null
+++ b/ext/pcre/tests/preg_replace_callback_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test preg_replace_callback() function : basic functionality
+--FILE--
+<?php
+/*
+* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
+* Function is implemented in ext/pcre/php_pcre.c
+*/
+/*
+* Basic test for preg_replace_callback
+*/
+$replacement = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); //array will have the default key values (0-9) and each value is the corresponding key written in words.
+function integer_word($matches) {
+ global $replacement;
+ return $replacement[$matches[0]]; //all examples will be looking for an integer value, if one is found it will be stored in $matches[0] which corresponds to a key in the $replacements array
+
+}
+$subject1 = 'there are 7 words in this sentence.';
+$new_subject1 = preg_replace_callback('/\d/', "integer_word", $subject1);
+print "$new_subject1 \n";
+$subject2 = '1 2 3 4 is now written in words';
+$new_subject2 = preg_replace_callback('/\d/', "integer_word", $subject2, 3); //limits to three replacements
+print "$new_subject2 \n";
+$subject3 = 'there are no numbers in this string';
+$new_subject3 = preg_replace_callback('/\d/', "integer_word", $subject3, 5, $count); //limites to five replacements and counts the number of replacements made ands stores in $count variable
+print "$new_subject3 \n";
+print $count;
+?>
+--EXPECTF--
+there are seven words in this sentence.
+one two three 4 is now written in words
+there are no numbers in this string
+0