# PHP split each paragraph into array (ok)

## [PHP split each paragraph into array](https://stackoverflow.com/questions/29966238/php-split-each-paragraph-into-array)

```
 <?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);
?>
```

## [PHP DOMDocument loadHTML not encoding UTF-8 correctly](https://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly)

```
$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);
?>
```
