Zend - The PHP Company




Menus & Navigation

Add Code


Spider-safe index.php/URL/decoding  

Type: application
Added by: yaragn1
Entered: 28/08/2001
Last modified: 08/12/2000
Rating: ***** (6 votes)
Views: 15923
Spider-safe index.php/URL/decoding. See John Coggeshall's excellent example of this.


<?php
// extract variables from directory style GETs 
$res explode("index.php/"$REQUEST_URI); 
If (
count($res) > 1) { 
    
// THANK YOU YARAGN@YARAGN.CO.UK FOR THIS WONDERFUL CODE. CAN I BE YOUR FRIEND. 
    
$rest explode("?",$res[1]); 
    
$vars explode("/"$rest[0]); 
    FOR (
$i=0$i count($vars); $i++) { 
        If (
substr($vars[$i],strlen($vars[$i])-2,2
== 
"[]") { 
            
$temp substr($vars[$i],0,strlen($vars 
[$i])-2); 
            ${
$temp}[] = $vars[$i+1]; 
        } Else { 
            If (isset(
$vars[$i+1])) ${$vars[$i]} = 
$vars[$i+1]; 
        } 
    
$i++; 


?>


Usage Example


put it at the top of your file, call the file with /something.php/something/else/somearray[]/val1/somearray[]/val2
and voila, you get $something = "else";
and a $somearray containing ("val1","val2");

so there.


Rate This Script





Search



This Category All Categories