Zend - The PHP Company




HTTP

Add Code


URL string from array of variables  

Type: code fragment
Added by: twilop
Entered: 16/11/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 5900
A simple function that takes an array such as HTTP_GET_VARS and creates an url variable string from the elements. This string can then be used in a link to another page. Especially useful for Last Page / Next Page / Modify Search buttons on search pages.


<?php
function array_to_url$values ){

    if( !
is_array$values ) ) return false;
    
    
$url '';
    
    
reset$values );

    while( list( 
$k$v ) = each$values ) ){
    
        if( !
is_object$v ) ){
        
            if( 
is_array$v ) ){
            
                
reset$v );
                
                while( list( 
$k2,$v2 ) = each$v ) ){
                    
$url .= $url == '' $k.'['.$k2.']='.urlencode$v2 ) : '&'.$k.'['.$k2.']='.urlencode$v2 );
                }
                
            }
            else{
                
$url .= $url == '' "$k=" urlencode$v ) : "&$k=" urlencode$v );
            }

        }

    }
    
    return 
$url;

}
?>


Usage Example


<?php
    $get_vars_string 
array_to_url$HTTP_GET_VARS );
?>


Rate This Script





Search



This Category All Categories