davblackpool Posted December 2, 2013 Share Posted December 2, 2013 Hi Everyone I'm getting really baffled by this and hope somebody can help. I have a PHP get variable as follows: eg: page.php?ad1=Any Road, London I am wanting my PHP page to split that in two to create 2 separate echo's.. I've managed the first one where I can get the first part before the comma but am struggling to get the second part after the commar on another one. This is the code I'm working with: <?php $ad1 =$_GET['ad1']; $exploded = explode(',', $ad1); $street1 = $exploded[0]; //Will contain part before % ?> <?php $ad1 =$_GET['ad1']; $exploded = explode(',', ',', $ad1); $town1 = $exploded[0]; //Will contain part before % ?> <?php echo "$street1"; ?> <?php echo "$town1"; ?> Street1 is working perfectly but I can't get town1 to work.. it should ideally echo London when working. Hope this makes sense, thanks in advance for any help Quote Link to comment https://forums.phpfreaks.com/topic/284448-php-explode-query/ Share on other sites More sharing options...
Solution Ch0cu3r Posted December 2, 2013 Solution Share Posted December 2, 2013 (edited) If this is all on the same page then there is no need to use explode again. Just use $explode[1] to get the town. $ad = $_GET['ad1']; $explode = explode(',', $ad); $street = $explode[0]; $town = $explode[1]; Edited December 2, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284448-php-explode-query/#findComment-1460948 Share on other sites More sharing options...
davblackpool Posted December 2, 2013 Author Share Posted December 2, 2013 Thank you so much Ch0cu3r That's worked brilliantly.. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/284448-php-explode-query/#findComment-1460951 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.