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&amp;sa=u&amp;ei=sf0jurmjic3nswb154cgdq&amp;ved=0cckqfjaa&amp;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('&amp;sa=(.*)" ', '" ', $serp); 

and doesn't work.

btw need restrict search preg_replace until first entrance, i.e. need replace html &amp;sa= first ", search &amp;sa= last "...

you missed delimiter. code looks like:

$serp = preg_replace('/&amp;sa=(.*)" /', '" ', $serp); 

okay, if want delete till first quote can try following instead of regex:

$temp = substr($serp,strpos($serp,'&amp;sa='),strpos($serp,'"',strpos($serp,'&amp;sa='))); $serp = str_replace($temp,"",$serp); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -