I have the following string
$searchlink = 'search-all.php?page=1&MakeId=BMW&BodyId=Coupe&ModelId=320&PriceToId=%C2%A3+20000&PriceFromId=%C2%A3+100&FuelId=Diesel&MilageId=%26gt%3B5000+miles+&DistanceId=%26gt%3B10+miles&AgeId=%26gt%3B1+years&postcodeId=&keywordId=&TransmissionId=Automatic&Search=Finddata';
and I tried with explode to split it by the =:
$searchlink = explode('=', $searchlink);
and the var_dump for this resulted
array(15) {
[0]=> string(19) "search-all.php?page"
[1]=> string(8) "1&MakeId"
[2]=> string(10) "BMW&BodyId"
[3]=> string(13) "Coupe&ModelId"
[4]=> string(13) "320&PriceToId"
[5]=> string(24) "%C2%A3+20000&PriceFromId"
[6]=> string(17) "%C2%A3+100&FuelId"
[7]=> string(15) "Diesel&MilageId"
[8]=> string(30) "%26gt%3B5000+miles+&DistanceId"
[9]=> string(22) "%26gt%3B10+miles&AgeId"
[10]=> string(26) "%26gt%3B1+years&postcodeId"
[11]=> string(10) "&keywordId"
[12]=> string(15) "&TransmissionId"
[13]=> string(16) "Automatic&Search"
[14]=> string(8) "Finddata"
So I tried doing another explode based on &
after the explode i have done, but resulted in a NULL
. Tried smth like $searchlink = explode('&', $searchlink)
.
My final code was:
<?php
$searchlink = 'search-all.php?page=1&MakeId=BMW&BodyId=Coupe&ModelId=320&PriceToId=%C2%A3+20000&PriceFromId=%C2%A3+100&FuelId=Diesel&MilageId=%26gt%3B5000+miles+&DistanceId=%26gt%3B10+miles&AgeId=%26gt%3B1+years&postcodeId=&keywordId=&TransmissionId=Automatic&Search=Finddata';
$searchlink = explode('=', $searchlink);
$searchlink = explode('&', $searchlink);
?>
The expected output would be
BMW 320 Coupe PricefromId 100 PricetoId 20000 FuelId Diesel MilageId 5000 DistanceId 10 AgeId 1 PostocodeId KeywordId TransmissionId Automatic.
Please help me on this I ran out of ideas. Your help will be much appreciated.