My regular comparison dish, there is now a regular replacement of the problem has been uncertain, the demand is this:
Some of the tags in the content
(这里有任意内容和标签)( 这里也有任意内容和标签)
Then the item is replaced with this:
(这里有任意内容和标签)( 这里也有任意内容和标签)
Simply said that the img outside the bread figure and then pulled out to put behind p, and then use preg_replace how to write it?
Reply content:
My regular comparison dish, there is now a regular replacement of the problem has been uncertain, the demand is this:
Some of the tags in the content
(这里有任意内容和标签)( 这里也有任意内容和标签)
Then the item is replaced with this:
(这里有任意内容和标签)( 这里也有任意内容和标签)
Simply said that the img outside the bread figure and then pulled out to put behind p, and then use preg_replace how to write it?
Can I understand that
Extract all the img tags under p to p, if it is multiple img, this needs to use Preg_match.
And there will be other labels in p, except P tags
If there's only one img inside,
//正则$p = '#
<> .*?)>(? .*?)(?\)(? .*?)
#i';//替换$r = ' $2$4
$3
';//原内容$s = '
fsdfsdfsfkolja;ad;lasd
';echo preg_replace($p, $r, $s);// 结果://
fsdfsdfsfkolja;ad;lasd
There are multiple img
$s = 'fsdfsdfsfkolja;ad;lasd
asdaa';echo preg_replace_callback('# <>
.*?)>(? .*?)
#', function($matches) { preg_match_all('##', $str = $matches[0], $matches1, PREG_OFFSET_CAPTURE ); foreach (array_reverse($matches1[0]) as $v) $str = substr_replace($str, '', $v[1], strlen($v[0])); return $str.'
'.implode('',array_map(function($v){return $v[0];}, $matches1[0])).'
';}, $s);// 结果://
fsdfsdfsfkolja;ad;lasd
asdaa