cmj Posted February 18, 2009 Share Posted February 18, 2009 Hey guys, i'm a forum dude myself, and realize that what I am doing is completely newbish, selfish, and on some levels... I'm not a PHP guy, but I just need a SIMPLE script. All I am doing is passing three strings through URI.. Example. I'll send a url that looks like this, to the script: /code.php?Good%20Afternoon%20CMJ I need to split the three 'variables' at the ascii space so I can utilize JUST the name (or third variable). Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/ Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 You may find explode useful. Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/#findComment-765404 Share on other sites More sharing options...
Maq Posted February 18, 2009 Share Posted February 18, 2009 Is there supposed to be a variable assigned to this URL? For example: /code.php?message=Good%20Afternoon%20CMJ Anyway, however you grab this string you have to decode it, explode it (as premiso mentioned) and assign a variable to the last piece of the array (assuming the last piece is going to always be the one you need). With a little tweaking, it should look something like: $string = urldecode("Good%20Afternoon%20CMJ"); $pieces = explode(" ", $string); foeach($pieces as $key => $value) { echo "key => " . $key . " value => " . $value; $name = $value; } ?> Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/#findComment-765420 Share on other sites More sharing options...
The Little Guy Posted February 18, 2009 Share Posted February 18, 2009 Is there supposed to be a variable assigned to this URL? For example: /code.php?message=Good%20Afternoon%20CMJ Anyway, however you grab this string you have to decode it, explode it (as premiso mentioned) and assign a variable to the last piece of the array (assuming the last piece is going to always be the one you need). With a little tweaking, it should look something like: <?php $string = urldecode("Good%20Afternoon%20CMJ"); $pieces = explode(" ", $string); foeach($pieces as $key => $value) { echo "key => " . $key . " value => " . $value; $name = $value; } ?> Why use a for each? He knows he wants, the third var. $string = urldecode("Good%20Afternoon%20CMJ"); list($v1,$v2,$v3) = explode(" ", $string); echo $v3; Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/#findComment-765461 Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 Why use a for each? He knows he wants, the third var. $string = urldecode("Good%20Afternoon%20CMJ"); list($v1,$v2,$v3) = explode(" ", $string); echo $v3; Sorry, I had to do this Why use a list why not just do this: $string = urldecode("Good%20Afternoon%20CMJ"); $var = explode(" ", $string); $var = $var[2]; echo $var; Since he only needs the 3rd one anyways. Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/#findComment-765465 Share on other sites More sharing options...
The Little Guy Posted February 18, 2009 Share Posted February 18, 2009 Why use a for each? He knows he wants, the third var. $string = urldecode("Good%20Afternoon%20CMJ"); list($v1,$v2,$v3) = explode(" ", $string); echo $v3; Sorry, I had to do this Why use a list why not just do this: $string = urldecode("Good%20Afternoon%20CMJ"); $var = explode(" ", $string); $var = $var[2]; echo $var; Since he only needs the 3rd one anyways. haha yeah I should have used that. list should be depreciated. Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/#findComment-765466 Share on other sites More sharing options...
Maq Posted February 18, 2009 Share Posted February 18, 2009 You guys are so smart! Link to comment https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/#findComment-765467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.