sanahoria Posted June 14, 2008 Share Posted June 14, 2008 So i have this function: function change_get_($varname,$value,$get) { if(strpos($get,"?") === false) { return "?$varname=$value"; } //get data empty, no ? if(strpos($get,"?") == strlen($get)-1) { return "$varname=$value"; } //get data empty $str = substr($get,strpos($get,"?")+1); if(strpos($str,$varname) === false) //var not in get data return $str . "&$varname=$value"; //var already exists in get data if(strpos($str, "&", strpos($str, $varname)) !== false) { //variable not last one $sub = substr($str,strpos($str, $varname),strpos($str,"&",strpos($str, $varname)) - strpos($str, $varname)); } else { //variable is last $sub = substr($str,strpos($str, $varname)); } $ret = str_replace($sub, $varname . "=" . $value, $str); return $ret; } function change_get($varname,$value) { change_get_($varname, $value, $_SERVER['REQUEST_URI']); } which works perfectly (btw if anyone knows of an easier way to do this without using forms please tell me). I know this because if I insert an "echo $ret" after $ret is declared it outputs the correct string. however if I reference the method later in away that forces it to get to the last return statement, I get absolutely no return value. for example if I call, echo "hello: " . change_get("num", 5); later in the code, when the URI is something like "test.php?num=4" the output is Hello: . Am I making a really stupid mistake? I have tried everything I could think of (returning the str_replace w/o the $ret variable, moving the functions to an external file that i then included, etc.) but nothing would work (although in each case if I added the echo "$ret" in the function I would get my desired output. This just won't work though, I need it to return a string. Thank you in advance Link to comment https://forums.phpfreaks.com/topic/110189-solved-strange-function-problems/ Share on other sites More sharing options...
kranthi117 Posted June 14, 2008 Share Posted June 14, 2008 change_get_($varname, $value, $_SERVER['REQUEST_URI']); shuld b replaced by return change_get_($varname, $value, $_SERVER['REQUEST_URI']); Link to comment https://forums.phpfreaks.com/topic/110189-solved-strange-function-problems/#findComment-565474 Share on other sites More sharing options...
sanahoria Posted June 14, 2008 Author Share Posted June 14, 2008 ahhh I knew it was something simple. Thanks so much. Link to comment https://forums.phpfreaks.com/topic/110189-solved-strange-function-problems/#findComment-565487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.