Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

PHP Explode Query

$
0
0

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 :)

Viewing all articles
Browse latest Browse all 13200

Trending Articles