Replace href in PHP
I'm trying to transform th开发者_C百科is:
http://link_brochure/1/2 OR link_brochure/1/2
into this:
class="show-brochure" href="http://localhost/main/brochure/1/2"
But I'm a rookie when it comes about regular expressions... Any ideas?
Thanks!
Something like this?
$str=preg_replace(
'{(?:http://)?link_brochure/(\d+)/(\d+)}',
'class="show-brochure" href="http://localhost/main/brochure/$1/$2"',
$str);
Edit: updated following question edit (Thanks Peter).
I'd just use str_replace to replace 'main/' with 'link_', then 'a ' with 'a class="show-brochure"'.
On iPad, so can't be bothered to type code, but look up str_replace, and you'll get the idea!
精彩评论