I am trying to remove some parameters from a URL using PHP preg_replace(). For example, i need to remove a[]=1
from the bellow URL.
$my_url = 'www.myhost.com/filter.php?a[]=1&a[]=12&a[]=13&a[]=14'
So i am using:
$without_filter = preg_replace("/(&)?a\[\]=1/", '', $my_url);
I want to remove only a[]=1
, but it is removing the portion that contains a[]=1
from the others parameters, so am i getting:
www.myhost.com/filter.php?234
Someone can help me to solve this?