[Solved] How to remove query string from “href” attribute of anchor using php?


Use /\?[^\"]+/ like bellow:

<?php
$string = '<a href="https://stackoverflow.com/title/tt3110958/?ref_=nm_flmg_act_2" style="color:#666" >';
$result = preg_replace("/\?[^\"]+/", "", $string);
echo $result;
?>

Output : <a href="https://stackoverflow.com/title/tt3110958/" style="color:#666" >

0

solved How to remove query string from “href” attribute of anchor using php?