PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 52 lines | 27 code | 11 blank | 14 comment | 2 complexity | 07c1a9ec27e0f7948fc981f587776c7e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : string strtr(string $str, string $from[, string $to]);
  3. string strtr(string $str, array $replace_pairs);
  4. * Description: Translates characters in str using given translation tables
  5. * Source code: ext/standard/string.c
  6. */
  7. /* Testing strtr() function by passing the
  8. * empty string & null for 'str' argument and
  9. * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments
  10. */
  11. <<__EntryPoint>> function main(): void {
  12. echo "*** Testing strtr() : empty string & null for 'str' arg ***\n";
  13. /* definitions of required input variables */
  14. $count = 1;
  15. $heredoc_str = <<<EOD
  16. EOD;
  17. //array of string inputs for $str
  18. $str_arr = varray[
  19. "",
  20. '',
  21. NULL,
  22. null,
  23. FALSE,
  24. false,
  25. $heredoc_str
  26. ];
  27. $from = "";
  28. $to = "TEST";
  29. $replace_pairs = darray["" => "t", '' => "TEST"];
  30. /* loop through to test strtr() with each element of $str_arr */
  31. for($index = 0; $index < count($str_arr); $index++) {
  32. echo "-- Iteration $count --\n";
  33. $str = $str_arr[$index]; //getting the array element in 'str' variable
  34. //strtr() call in three args syntax form
  35. try { var_dump( strtr($str, $from, $to) ); } catch (Exception $e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n"; }
  36. //strtr() call in two args syntax form
  37. try { var_dump( strtr($str, $replace_pairs) ); } catch (Exception $e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n"; }
  38. $count++;
  39. }
  40. echo "*** Done ***";
  41. }