3v4l.org

run code in 300+ PHP versions simultaneously
<?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; echo "【RESULT 1】\n\n"; echo preg_replace_callback( '@(<br[^>]*+>)|\s?</?+p>\s?|(?<=<t(?:r|d))[^>]*+(?=>)@', function ($matches) { return isset($matches[1]) ? '、' : ''; }, $text1 ); echo "\n\n【RESULT 2】\n\n"; echo preg_replace_callback( '@(<br[^>]*+>)|\s*+</?+p>\s*+|(?<=<t(?:r|d))[^>]*+(?=>)@', function ($matches) { return isset($matches[1]) ? '、' : ''; }, $text2 );

preferences:
44.76 ms | 402 KiB | 5 Q