-1

how to pass variable in get without %20 %27 and retrieve back exactly what is passed i tried urlencode and decode but not works need some help

passing in url http://localhost/civilhelp/enquiry.php?cat=%27PLUMBING%20FITTINGS%20&%20SANITARY%20WARE%27 i need to remove %27 %20 used urlencode but no use

retrive only PLUMBING FITTINGS and remaining pls anybody help with a solution

i am passing it as

 $cate = 'PLUMBING FITTINGS & SANITARY WARE'; it is from db
    <a href="enquiry.php?cat='<?php echo urlencode($cate)  ;?>'"> 

try to retrieve as

$category = urldecode($_GET['cat']); 
$category = str_replace("'"," ",$category);
print_r($category); 
$category = trim($category);

print_r($category); it just prints PLUMBING FITTINGS

Am not getting exactly aht i passed Note: I have used urlencode and urldecode also trim

But still i can't Hope what is my problem!!

jh314
  • 27,144
  • 16
  • 62
  • 82

2 Answers2

0

that cannot be right i tried your code and it show the correct data try this

$url = 'http://localhost/civilhelp/enquiry.php?cat=%27PLUMBING%20FITTINGS%20&%20SANITARY%20WARE%27';
$category = urldecode($url);
$category = str_replace("'","",$category);
echo $category; // result: http://localhost/civilhelp/enquiry.php?cat=PLUMBING FITTINGS & SANITARY WARE

EDIT:
i got your problem just in the cat='' change & to %26

Mohamed Belal
  • 610
  • 7
  • 11
-1
<?php  if(!empty($r['category'])){ $cat = $r['category']; $cate=substr($cat,0,25) . '';
 //$cat = str_replace(' ', '', $cate);
  $cat = str_replace('&', '%26', $cat);  after changing it works fine // print_r($cat);?>
  <a href="enquiry.php?cat='<?php echo $cat  ;?>'">

enter code here