PageRenderTime 41ms CodeModel.GetById 29ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/stripslashes_variation2.php

https://github.com/beenanner/hhvm
PHP | 103 lines | 86 code | 6 blank | 11 comment | 0 complexity | f38f5815f22d7a61c6f5c9b511f12d7f MD5 | raw file
  1<?php
  2/* Prototype  : string stripslashes ( string $str )
  3 * Description: Returns an un-quoted string
  4 * Source code: ext/standard/string.c
  5*/
  6
  7/*
  8 * Test stripslashes() with various strings containing characters thats can be backslashed.
  9 * First adding slashes using addslashes() and then removing the slashes using stripslashes() 
 10*/
 11
 12echo "*** Testing stripslashes() : with various strings containing backslashed characters ***\n";
 13
 14// initialising a heredoc string
 15$heredoc_string = <<<EOT
 16This is line 1 of 'heredoc' string
 17This is line 2 of "heredoc" string
 18EOT;
 19
 20$heredoc_null_string =<<<EOT
 21EOT;
 22$heredoc_string_only_backslash =<<<EOT
 23\
 24EOT;
 25$heredoc_string_only_single_quote =<<<EOT
 26'
 27EOT;
 28$heredoc_string_only_double_quote =<<<EOT
 29"
 30EOT;
 31 
 32// initialising the string array
 33
 34$str_array = array( 
 35                    // string without any characters that can be backslashed
 36                    'Hello world',
 37 
 38                    // string with single quotes
 39                    "how're you doing?", 
 40                    "don't disturb u'r neighbours",
 41                    "don't disturb u'r neighbours''",
 42                    '',
 43                    '\'',
 44                    "'",
 45                    $heredoc_string_only_single_quote,
 46                    
 47                    // string with double quotes
 48                    'he said, "he will be on leave"',
 49                    'he said, ""he will be on leave"',
 50                    '"""PHP"""',
 51                    "",
 52                    "\"",
 53                    '"',
 54 		    "hello\"",
 55                    $heredoc_string_only_double_quote,
 56                         
 57                    // string with backslash characters
 58                    'Is your name Ram\Krishna?',
 59                    '\\0.0.0.0',
 60                    'c:\php\testcase\stripslashes',
 61                    '\\',
 62                    $heredoc_string_only_backslash,
 63
 64                    // string with nul characters
 65                    'hello'.chr(0).'world',
 66                    chr(0).'hello'.chr(0),
 67                    chr(0).chr(0).'hello',
 68                    chr(0),
 69
 70                    // mixed strings
 71                    "'\\0.0.0.0'",
 72                    "'\\0.0.0.0'".chr(0),
 73                    chr(0)."'c:\php\'",
 74                    '"\\0.0.0.0"',
 75                    '"c:\php\"'.chr(0)."'",
 76                    '"hello"'."'world'".chr(0).'//',
 77
 78		    // string with hexadecimal number
 79                    "0xABCDEF0123456789",
 80                    "\x00",
 81                    '!@#$%&*@$%#&/;:,<>',
 82                    "hello\x00world",
 83
 84                    // heredoc strings
 85                    $heredoc_string,
 86                    $heredoc_null_string
 87                  );
 88
 89$count = 1;
 90// looping to test for all strings in $str_array
 91foreach( $str_array as $str )  {
 92  echo "\n-- Iteration $count --\n";
 93  $str_addslashes = addslashes($str);
 94  var_dump("The string after addslashes is:", $str_addslashes);
 95  $str_stripslashes = stripslashes($str_addslashes);
 96  var_dump("The string after stripslashes is:", $str_stripslashes);
 97  if( strcmp($str, $str_stripslashes) != 0 )
 98    echo "\nError: Original string and string from stripslash() donot match\n";
 99  $count ++;
100}
101
102echo "Done\n";
103?>