php - How to use preg_replace to remove part of url address? -
i have html code this:
<a href="http://mysite.com/documentos/servicios/sucre/sucdoc19.pdf&sa=u&ei=sf0jurmjic3nswb154cgdq&ved=0cckqfjaa&usg=afqjcngfxg_9x83u3pyr6jfkjcwuxv8x0q">
i need clean code
<a href="http://mysite.com/documentos/servicios/sucre/sucdoc19.pdf">
using preg_replace
.
my code following:
$serp = preg_replace('&sa=(.*)" ', '" ', $serp);
and doesn't work.
btw need restrict search preg_replace until first entrance, i.e. need replace html &sa=
first "
, search &sa=
last "
...
you missed delimiter. code looks like:
$serp = preg_replace('/&sa=(.*)" /', '" ', $serp);
okay, if want delete till first quote can try following instead of regex:
$temp = substr($serp,strpos($serp,'&sa='),strpos($serp,'"',strpos($serp,'&sa='))); $serp = str_replace($temp,"",$serp);
Comments
Post a Comment