我有两个字符串
$xml = '—To 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.';
$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';我需要找到 protocol这种标签,并在$tex中找到相同的文字,并用{it protocol }替换"protocol"这个字。
只是
我需要找到这种模式
protocol并找到该模式内的文本并替换$ tex中的相同单词。
仅供参考:内容方面均相同$tex和$xml。
我用这个代码
preg_match_all('/(.*?)(.*?)\',$xml,$matches);
for($i=0;$i
{
$findtext = str_replace("
$replace = "{\it".$matches[1][$i]."}".$matches[2][$i];
$finaltext = preg_replace('/'.$findtext.'/',$replace,$tex);
}
echo $finaltext;但它只替换一个。