I need to extract subject/body of an email message generated by a form in Joomla. I am using some tags for defining different subjects/body for each language, like:
{lang en}English Text{/lang}
{lang it}Italian Text{/lang}
{lang fr}French Text{/lang}
I have the following code for striping Text from Subjects in different languages:
$msgSubject = $template->subject;
if ($language=='it-IT')
{
preg_match('~{lang it}([^{]*){/lang}~i', $msgSubject, $match);
$msgSubject=($match[1]);
}
elseif ($language=='en-GB')
{
preg_match('~{lang en}([^{]*){/lang}~i', $msgSubject, $match);
$msgSubject=($match[1]);
}
and so on for other languages. It works perfectly for the subjects of the emails, which is just plain text. If I do the same on the Body, wich is a string containing HTML elemnes like p and br, and so on, it doesn't work.... Code sample:
$msgBody = $template->body;
if ($language=='it-IT')
{
preg_match('~{lang it}([^{]*){/lang}~i', $msgBody, $match);
$msgBody=($match[1]);
}
elseif ($language=='en-GB')
{
preg_match('~{lang en}([^{]*){/lang}~i', $msgBody, $match);
$msgBody=($match[1]);
}
it simply outputs nothing. What should I change in the preg_match function to avoid mass with HTML tags?
Click on preg_match_all
Is this what you want? Works for me..
http://www.phpliveregex.com/p/fkB
Edit:
If you do like this:
http://www.phpliveregex.com/p/fkF
You capture the language too and you don't need the ifs.