Pack Hack
Pack Hack

Reputation: 109

Help to write regex using php

I have a URL where I want to replace the equal to (=) next to &c and &app with %3d using php

$ddd_url = '<asset ="http://www.ggtt.com/dfghdzHV8?f=videos&c=AIfgdfdfVQQ93m-ikEn0N3FqIfgdf45tdgdsHuwtysV-I8SEdfsgdf44xmNPW_B-kX33bw&app=dde_gdata"/>';

I also want to remove the _8 from the $thumbnail

$thumbnail = "http://d2dsfsd.humbnails/20415/33-d148-45b1-9098-11e5c/thumbnail_8.jpg";

Upvotes: 0

Views: 92

Answers (2)

fin1te
fin1te

Reputation: 4351

Try this regex

$result = preg_replace('/(&c|&app)(=)/i', '$1%3d', $ddd_url);

Upvotes: 0

dynamic
dynamic

Reputation: 48141

str_replace( array( '&c='   , '&app='   ), 
             array( '&c%3d' , '&app%3d' ), 
             $url
           );

Avoid regex when possible.

Upvotes: 3

Related Questions