1

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?

1
  • You should investigate a template engine like smarty. Commented Aug 23, 2011 at 18:51

1 Answer 1

3

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.