Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 20 votes, 3.30 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2005, 03:12 PM   PM User | #1
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
Replace url variable / add variable function.

Hey everyone,
This is the function I use when replacing url variables, or adding a new variable.

I realize there are holes but for the most part as long as there are no crazy characters in the url or the variables you will be ok.

PHP Code:
function replaceUrl($url,$uKey,$uVal){
    
$Qurl explode("?",$url);
    
$arr explode("&",$Qurl[1]);
    
$r ''$set 0;
    for(
$i=0;$i<sizeof($arr);$i++){
        
$arr2 explode("=",$arr[$i]);
        if(
$arr2[0] == $uKey){
            
$arr2[1] = $uVal;
            
$set 1;
        }
        
$r.=$arr2[0]."=".$arr2[1]."&";
    }
    if(
$set == 0){
        
$r.= $uKey."=".$uVal;
    } else {
        
$r rtrim($r"&");
    }
    return 
$Qurl[0].'?'.$r;

usage:

PHP Code:

print replaceUrl('http://yourDomain.com/index.php?test=1&name=rlemon&age=19','name','rob lemon'); 
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:53 AM.


Advertisement
Log in to turn off these ads.