1--TEST-- 2Test nl2br() function : usage variations - double quoted strings for 'str' argument 3--FILE-- 4<?php 5/* Prototype : string nl2br(string $str); 6 * Description: Inserts HTML line breaks before all newlines in a string 7 * Source code: ext/standard/string.c 8*/ 9 10/* Test nl2br() function by passing double quoted strings containing various 11 * combinations of new line chars to 'str' argument 12*/ 13 14echo "*** Testing nl2br() : usage variations ***\n"; 15 16$strings = array( 17 //new line chars embedded in strings 18 "Hello\nWorld", 19 "\nHello\nWorld\n", 20 "Hello\rWorld", 21 "\rHello\rWorld\r", 22 "Hello\r\nWorld", 23 "\r\nHello\r\nWorld\r\n", 24 25 //one blank line 26 " 27", 28 29 //two blank lines 30 " 31 32", 33 34 //inserted new line in a string 35 "Hello 36World" 37); 38 39//loop through $strings array to test nl2br() function with each element 40$count = 1; 41foreach( $strings as $str ){ 42 echo "-- Iteration $count --\n"; 43 var_dump(nl2br($str) ); 44 $count ++ ; 45} 46echo "Done"; 47?> 48--EXPECTF-- 49*** Testing nl2br() : usage variations *** 50-- Iteration 1 -- 51string(17) "Hello<br /> 52World" 53-- Iteration 2 -- 54string(31) "<br /> 55Hello<br /> 56World<br /> 57" 58-- Iteration 3 -- 59string(17) "Hello<br /> 59World" 60-- Iteration 4 -- 61string(31) "<br /> 61Hello<br /> 61World<br /> 61" 62-- Iteration 5 -- 63string(18) "Hello<br /> 64World" 65-- Iteration 6 -- 66string(34) "<br /> 67Hello<br /> 68World<br /> 69" 70-- Iteration 7 -- 71string(7) "<br /> 72" 73-- Iteration 8 -- 74string(14) "<br /> 75<br /> 76" 77-- Iteration 9 -- 78string(17) "Hello<br /> 79World" 80Done 81