i have two strings
$xml = '<para aid:pstyle="NL_FIRST">—To the best of our knowledge, the MMSN<emph aid:cstyle="ITALIC"> protocol</emph> is the first multifrequency<emph aid:cstyle="ITALIC"> MAC protocol especially</emph> designed for WSNs, in which each device is equipped with a single radio transceiver and the MAC layer packet size is very small.</para></item><item>';
$tex = '\begin{itemize}\item o the best of our knowledge, the MMSN protocol is the first multifrequency MAC protocol especially designed for WSNs, in which each device is equipped with a single radio transceiver and the MAC layer packet size is very small.\item';
I need to find <emph aid:cstyle="ITALIC"> protocol</emph> This kind of tag and find the same text in $tex and replace the word "protocol" with {it protocol } .
Simply
i need to find this pattern
<emph aid:cstyle="ITALIC"> protocol</emph>
and find the text inside that pattern and replace the same word in $tex.
FYI : Content-wise both are same $tex and $xml.
I used this code
preg_match_all('/<emph aid:cstyle="ITALIC">(.*?)<\/emph>(.*?)\</',$xml,$matches);
for($i=0;$i<count($matches[1]);$i++)
{
$findtext = str_replace("<","",$matches[1][$i].$matches[2][$i]);
$replace = "{\it".$matches[1][$i]."}".$matches[2][$i];
$finaltext = preg_replace('/'.$findtext.'/',$replace,$tex);
}
echo $finaltext;
But it replace only one.