1--TEST--
2Test nl2br() function : usage variations - single 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 single quoted strings containing various
11 *   combinations of new line chars to 'str' argument
12*/
13
14echo "*** Testing nl2br() : usage variations ***\n";
15$strings = array(
16  '\n',
17  '\r',
18  '\r\n',
19  'Hello\nWorld',
20  'Hello\rWorld',
21  'Hello\r\nWorld',
22
23  //one blank line
24  '
25',
26
27  //two blank lines
28  '
29
30',
31
32  //inserted new line
33  'Hello
34World'
35);
36
37//loop through $strings array to test nl2br() function with each element
38$count = 1;
39foreach( $strings as $str ){
40  echo "-- Iteration $count --\n";
41  var_dump(nl2br($str) );
42  $count ++ ;
43}
44echo "Done";
45?>
46--EXPECTF--
47*** Testing nl2br() : usage variations ***
48-- Iteration 1 --
49string(2) "\n"
50-- Iteration 2 --
51string(2) "\r"
52-- Iteration 3 --
53string(4) "\r\n"
54-- Iteration 4 --
55string(12) "Hello\nWorld"
56-- Iteration 5 --
57string(12) "Hello\rWorld"
58-- Iteration 6 --
59string(14) "Hello\r\nWorld"
60-- Iteration 7 --
61string(7) "<br />
62"
63-- Iteration 8 --
64string(14) "<br />
65<br />
66"
67-- Iteration 9 --
68string(17) "Hello<br />
69World"
70Done
71