- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
<?php
$text1 = <<<EOD
<tr class="aaa">
<td class="bbb">
<p>
あああああ
</p>
</td>
<tr>
EOD;
$text2 = <<<EOD
<tr class="aaa">
<td class="bbb">
あああああ
</td>
<tr>
EOD;
$text1 = preg_replace_callback(
'@(<br[^>]*+>)|\s*+</?+p>\s*+|(?<=<t(?:r|d))[^>]*+(?=>)@',
function ($matches) {
return isset($matches[1]) ? '、' : '';
},
$text1
);
$text2 = preg_replace_callback(
'@(<br[^>]*+>)|</?+p>|(?<=<t(?:r|d))[^>]*+(?=>)@',
function ($matches) {
return isset($matches[1]) ? '、' : '';
},
$text2
);
var_dump($text1, $text2);