😃PHP split each paragraph into array (ok)

 <?php
$text = <<<TEXT
    <p>Hello!</p>
    <p style="border: 1px solid black;">How are you,<br /> today?</p>
TEXT;

$dom = new DOMDocument();
$paragraphs = array();
$dom->loadHTML($text);
foreach($dom->getElementsByTagName('p') as $node)
{

    $paragraphs[] = $dom->saveHTML($node);

}
print_r($paragraphs);
?>

$profile = '<p>イリノイ州シカゴにて、アイルランド系の家庭に、9</p>';
$dom = new DOMDocument();
$dom->loadHTML(mb_convert_encoding($profile, 'HTML-ENTITIES', 'UTF-8'));
echo $dom->saveHTML();

Full

<?php
$text = <<<TEXT
    <p>Hello!</p>
    <p style="border: 1px solid black;">How are you,<br /> today?</p>
TEXT;

$dom = new DOMDocument();
$paragraphs = array();
$dom->loadHTML(mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8'));
foreach($dom->getElementsByTagName('p') as $node)
{

    $paragraphs[] = $dom->saveHTML($node);

}
print_r($paragraphs);
?>

Last updated