PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/library/xmlrpc/xmlrpc/compat/var_export.php

https://bitbucket.org/zxcmehran/arta
PHP | 105 lines | 43 code | 8 blank | 54 comment | 9 complexity | 05e437537fcbec3a9f6e0d2ba5af4daa MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0, Apache-2.0
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license, |
  8. // | that is bundled with this package in the file LICENSE, and is |
  9. // | available at through the world-wide-web at |
  10. // | http://www.php.net/license/3_0.txt. |
  11. // | If you did not receive a copy of the PHP license and are unable to |
  12. // | obtain it through the world-wide-web, please send a note to |
  13. // | license@php.net so we can mail you a copy immediately. |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Aidan Lister <aidan@php.net> |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: var_export.php,v 1.2 2005/11/21 10:57:23 ggiunta Exp $
  19. /**
  20. * Replace var_export()
  21. *
  22. * @category PHP
  23. * @package PHP_Compat
  24. * @link http://php.net/function.var_export
  25. * @author Aidan Lister <aidan@php.net>
  26. * @version $Revision: 1.2 $
  27. * @since PHP 4.2.0
  28. * @require PHP 4.0.0 (user_error)
  29. */
  30. if (!function_exists('var_export')) {
  31. function var_export($array, $return = false, $lvl=0)
  32. {
  33. // Common output variables
  34. $indent = ' ';
  35. $doublearrow = ' => ';
  36. $lineend = ",\n";
  37. $stringdelim = '\'';
  38. // Check the export isn't a simple string / int
  39. if (is_string($array)) {
  40. $out = $stringdelim . str_replace('\'', '\\\'', str_replace('\\', '\\\\', $array)) . $stringdelim;
  41. } elseif (is_int($array) || is_float($array)) {
  42. $out = (string)$array;
  43. } elseif (is_bool($array)) {
  44. $out = $array ? 'true' : 'false';
  45. } elseif (is_null($array)) {
  46. $out = 'NULL';
  47. } elseif (is_resource($array)) {
  48. $out = 'resource';
  49. } else {
  50. // Begin the array export
  51. // Start the string
  52. $out = "array (\n";
  53. // Loop through each value in array
  54. foreach ($array as $key => $value) {
  55. // If the key is a string, delimit it
  56. if (is_string($key)) {
  57. $key = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $key));
  58. $key = $stringdelim . $key . $stringdelim;
  59. }
  60. $val = var_export($value, true, $lvl+1);
  61. // Delimit value
  62. /*if (is_array($value)) {
  63. // We have an array, so do some recursion
  64. // Do some basic recursion while increasing the indent
  65. $recur_array = explode($newline, var_export($value, true));
  66. $temp_array = array();
  67. foreach ($recur_array as $recur_line) {
  68. $temp_array[] = $indent . $recur_line;
  69. }
  70. $recur_array = implode($newline, $temp_array);
  71. $value = $newline . $recur_array;
  72. } elseif (is_null($value)) {
  73. $value = 'NULL';
  74. } else {
  75. $value = str_replace($find, $replace, $value);
  76. $value = $stringdelim . $value . $stringdelim;
  77. }*/
  78. // Piece together the line
  79. for ($i = 0; $i < $lvl; $i++)
  80. $out .= $indent;
  81. $out .= $key . $doublearrow . $val . $lineend;
  82. }
  83. // End our string
  84. for ($i = 0; $i < $lvl; $i++)
  85. $out .= $indent;
  86. $out .= ")";
  87. }
  88. // Decide method of output
  89. if ($return === true) {
  90. return $out;
  91. } else {
  92. echo $out;
  93. return;
  94. }
  95. }
  96. }
  97. ?>