开发者

Replace href in PHP

开发者 https://www.devze.com 2023-01-07 05:07 出处:网络
I\'m trying to transform th开发者_C百科is: http://link_brochure/1/2 OR link_brochure/1/2 into this:

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消