summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings/nl2br_variation1.phpt
blob: ab15ca1fe4be989e9512f42d6f21e791fced5b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--TEST--
Test nl2br() function : usage variations - double quoted strings for 'str' argument
--FILE--
<?php
/* Prototype  : string nl2br(string $str);
 * Description: Inserts HTML line breaks before all newlines in a string
 * Source code: ext/standard/string.c
*/

/* Test nl2br() function by passing double quoted strings containing various 
 *   combinations of new line chars to 'str' argument
*/

echo "*** Testing nl2br() : usage variations ***\n";

$strings = array(
  //new line chars embedded in strings
  "Hello\nWorld",
  "\nHello\nWorld\n",
  "Hello\rWorld",
  "\rHello\rWorld\r",
  "Hello\r\nWorld",
  "\r\nHello\r\nWorld\r\n",

  //one blank line 
  "
",

  //two blank lines
  "

",

  //inserted new line in a string
  "Hello
World"
);

//loop through $strings array to test nl2br() function with each element
$count = 1;
foreach( $strings as $str ){
  echo "-- Iteration $count --\n";
  var_dump(nl2br($str) );
  $count ++ ;
}
echo "Done";
?>
--EXPECTF--
*** Testing nl2br() : usage variations ***
-- Iteration 1 --
string(17) "Hello<br />
World"
-- Iteration 2 --
string(31) "<br />
Hello<br />
World<br />
"
-- Iteration 3 --
string(17) "Hello<br />
World"
-- Iteration 4 --
string(31) "<br />
Hello<br />
World<br />
"
-- Iteration 5 --
string(18) "Hello<br />
World"
-- Iteration 6 --
string(34) "<br />
Hello<br />
World<br />
"
-- Iteration 7 --
string(7) "<br />
"
-- Iteration 8 --
string(14) "<br />
<br />
"
-- Iteration 9 --
string(17) "Hello<br />
World"
Done