Text_PathNavigator
[ class tree: Text_PathNavigator ] [ index: Text_PathNavigator ] [ all elements ]

Source for file path.php

Documentation is available at path.php

  1. <?php
  2.  
  3. require_once 'Text/PathNavigator.php';
  4.  
  5. $p = new Text_PathNavigator('/the/golden/path''/');
  6.  
  7. echo "<b>$p->path</b>";
  8.  
  9. echo '<br><br>indexing methods';
  10. echo '<br>get(2)='.$p->get(2);
  11. echo '<br>get(golden)='.$p->get('golden');
  12.  
  13. echo '<br><br>slicing';
  14. echo '<br>slice(1)='.$p->slice(1);
  15. echo '<br>slice(-2,1)='.$p->slice(-21);
  16. echo '<br>slice(-1)='.$p->slice(-1);
  17.  
  18. echo '<br><br>normalizing path according to slash value "/"';
  19. echo '<br>original path="\test\ok\2\3\"';
  20. $p->load('\test\ok\2\3');
  21. echo '<br>normalized path='.$p->path;
  22.  
  23. echo '<br><br>loading from arrays and strings';
  24. $p->load(array('test'=>'ok'23));
  25. echo '<br>from array='.$p->path;
  26. $p->load('/test/ok/2/3');
  27. echo '<br>from string='.$p->path;
  28.  
  29. echo '<br><br>toArray with no offset<br>';
  30. print_r($p->toArray());
  31.  
  32. echo '<br><br>toArray with offset 1<br>';
  33. print_r($p->toArray(1));
  34.  
  35. if ($nodes $p->getIterator()) {
  36.     echo '<br><br>using an ArrayIterator';
  37.     foreach ($nodes as $i => $node{
  38.         echo "<br>$i = $node";
  39.     }
  40. }
  41.  
  42. /*
  43.  
  44. EXAMPLE OUTPUT
  45.  
  46. the/golden/path
  47.  
  48. indexing methods
  49. get(2)=path
  50. get(golden)=path
  51.  
  52. slicing
  53. slice(1)=golden/path
  54. slice(-2,1)=golden
  55. slice(-1)=path
  56.  
  57. normalizing path according to slash value "/"
  58. original path="\test\ok\2\3\"
  59. normalized path=test/ok/2/3
  60.  
  61. loading from arrays and strings
  62. from array=test/ok/2/3
  63. from string=test/ok/2/3
  64.  
  65. toArray with no offset
  66. Array ( [test] => ok [2] => 3 )
  67.  
  68. toArray with offset 1
  69. Array ( [ok] => 2 [3] => )
  70.  
  71. using an ArrayIterator
  72. 0 = test
  73. 1 = ok
  74. 2 = 2
  75. 3 = 3
  76.  
  77. */
  78.  
  79. ?>

Documentation generated on Mon, 11 Mar 2019 15:48:42 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.