Jump to content

PHP Explode Query


davblackpool
Go to solution Solved by Ch0cu3r,

Recommended Posts

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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.