开发者

PHP - regex parse template variable

I have to parse this template string variable, for example:

$str = "<p>Don't want to receive email notifications? %%UNSUBSCRIBE['Adjust your message settings']%% values in your privacy.</p>";

开发者_开发问答My result should be this:

"<p>Don't want to receive email notifications? <a href='http://www.example.com/'>Adjust your message settings</a> values in your privacy.</p>"

How to do this in php/regex?


Well heres a regex that matches that placeholder & captures 2 possible variables inside it which you might need:

%%(UNSUBSCRIBE)\[\'(.*?)\'\]%%

Something like preg_replace("/%%(UNSUBSCRIBE)\[\'(.*?)\'\]%%/", "$1$2", $string) should replace the whole placeholder with just the variables (the $1 and $2 represent the captured matches)...

Good luck!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜