1

I have url like this :

/leads/set_attributes.html?lead_id=3793&name=TEST

I need remove 'name' and return url. I try do it like this:

$vars = [];

parse_str(html_entity_decode($sAddQuery), $vars);

unset($vars['name']);

$sAddQuery = http_build_query($vars);

But i always get

%3Flead_id=3793

as result. I tried use html_entity_decode for array elements but it did not help. How can i solve this? Thanks

2
  • 1
    What is in $sAddQuery? The entire /leads/set_attributes.html?lead_id=3793&name=TEST path or only the query string? Commented Feb 16, 2021 at 10:30
  • Either way, html_entity_decode is unnecessary here. Here's a related question. Commented Feb 16, 2021 at 10:39

1 Answer 1

1

Modify your code to :

 <?php
   $url = parse_url('/leads/set_attributes.html?lead_id=3793&name=TEST');
   $str = $url['query'];
   parse_str($str, $params);  //parse URL
   unset($params['name']);   //unset name parameter
   $string = http_build_query($params);   //again built the URL string
   var_dump($string);
 ?>

Hope it works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.