fork download
  1. <?php
  2.  
  3. parseURI( '"linktext":http://w...content-available-to-author-only...u.nl#Frag' );
  4.  
  5. function parseURI( $uri)
  6. {
  7. $r1 = '~
  8. ^
  9. ( # 1 (optional)
  10. (?<scheme> [^:/?#]+ ) : # 2 <scheme>
  11. )?
  12. ( # 3 (optional)
  13. // (?<authority> [^/?#]* ) # 4 <authority>
  14. )?
  15. (?<path> [^?#]* ) # 5 <path> (required)
  16. ( # 6 (optional)
  17. \? (?<query> [^#]* ) # 7 <query>
  18. )?
  19. ( # 8 (optional)
  20. \# (?<fragment> .* ) # 9 <fragment>
  21. )# required?
  22. ~x';
  23.  
  24. #
  25. # scheme = $2
  26. # authority = $4
  27. # path = $5
  28. # query = $7
  29. # fragment = $9
  30.  
  31. echo ("$r1\n");
  32. echo ("$uri\n");
  33.  
  34. if( preg_match($r1, $uri, $m)) {
  35. print_r($m);
  36. }
  37. else {
  38. echo("did not match '$uri'\n");
  39. }
  40.  
  41. echo ("===========================\n");
  42.  
  43. $r2 = '~^((?<scheme>[^:/?#]+):)?(//(?<authority>[^/?#]*))?(?<path>[^?#]*)(\?(?<query>[^#]*))?(#(?<fragment>.*))?~';
  44.  
  45. if( preg_match( $r2, $uri, $m)) {
  46. print_r($m);
  47. }
  48. else {
  49. echo("did not match '$uri'\n");
  50. }
  51.  
  52.  
  53. $r3 = '~
  54. ^(
  55. ([^:/?#]+)
  56. :
  57. )?
  58. (
  59. //
  60. ([^/?#]*)
  61. )?
  62. ([^?#]*)
  63. (
  64. \?
  65. ([^#]*)
  66. )?
  67. (
  68. \#
  69. (.*)
  70. )?
  71. ~x';
  72.  
  73. echo ("===========================\n");
  74.  
  75. if( preg_match( $r3, $uri, $m)) {
  76. print_r($m);
  77. }
  78. else {
  79. echo("did not match '$uri'\n");
  80. }
  81.  
  82. $r4 = '~^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?~';
  83.  
  84. echo ("===========================\n");
  85.  
  86. if( preg_match( $r4, $uri, $m)) {
  87. print_r($m);
  88. }
  89. else {
  90. echo("did not match '$uri'\n");
  91. }
  92. }
  93.  
  94. ?>
  95.  
Success #stdin #stdout 0.03s 13112KB
stdin
Standard input is empty
stdout
~
   ^
    (                               # 1 (optional)
       (?<scheme> [^:/?#]+ ) :         # 2 <scheme>
    )?
    (                               # 3 (optional)
       // (?<authority> [^/?#]* )      # 4 <authority>
    )?
    (?<path> [^?#]* )               # 5 <path>  (required)
    (                               # 6 (optional)
      \? (?<query> [^#]* )             # 7 <query>
    )?
    (                               # 8 (optional)
      \# (?<fragment> .* )             # 9 <fragment>
    )# required?
  ~x
"linktext":http://w...content-available-to-author-only...u.nl#Frag
Array
(
    [0] => "linktext":http://w...content-available-to-author-only...u.nl#Frag
    [1] => "linktext":
    [scheme] => "linktext"
    [2] => "linktext"
    [3] => 
    [authority] => 
    [4] => 
    [path] => http://w...content-available-to-author-only...u.nl
    [5] => http://w...content-available-to-author-only...u.nl
    [6] => 
    [query] => 
    [7] => 
    [8] => #Frag
    [fragment] => Frag
    [9] => Frag
)
===========================
Array
(
    [0] => "linktext":http://w...content-available-to-author-only...u.nl#Frag
    [1] => "linktext":
    [scheme] => "linktext"
    [2] => "linktext"
    [3] => 
    [authority] => 
    [4] => 
    [path] => http://w...content-available-to-author-only...u.nl
    [5] => http://w...content-available-to-author-only...u.nl
    [6] => 
    [query] => 
    [7] => 
    [8] => #Frag
    [fragment] => Frag
    [9] => Frag
)
===========================
Array
(
    [0] => "linktext":http://w...content-available-to-author-only...u.nl#Frag
    [1] => "linktext":
    [2] => "linktext"
    [3] => 
    [4] => 
    [5] => http://w...content-available-to-author-only...u.nl
    [6] => 
    [7] => 
    [8] => #Frag
    [9] => Frag
)
===========================
Array
(
    [0] => "linktext":http://w...content-available-to-author-only...u.nl#Frag
    [1] => "linktext":
    [2] => "linktext"
    [3] => 
    [4] => 
    [5] => http://w...content-available-to-author-only...u.nl
    [6] => 
    [7] => 
    [8] => #Frag
    [9] => Frag
)