Question: I want to extract the description of a page that have the following description format. Even though I believe I am correct, I do not get it.

```
$file_string = file_get_contents('');

preg_match('/<div class="description">(.*)<\/div>/i', $file_string, $descr);
$descr_out = $descr[1];

echo $descr_out; 

<div class="description">
<p>some text here</p>
</div>

```

Answer: 
It looks like you need to turn on single line mode in your regex. Modify it to add the -s flag:

```
preg_match('/<div class="description">(.*)<\/div>/si', $file_string, $descr);

```

Single line mode allows the . character to match newline characters. Without it, .\* will not match newlines, which you have between the opening and closing div tags.
I would recommend to use [DOMDocument](http://www.php.net/manual/en/class.domdocument.php) classes and [xpath](http://www.php.net/manual/en/class.domxpath.php) to extract random pieces from HTML documents, regexp based solutions are pretty brittle on changing input (adding an extra attribute, whitespace in strange places, etc.) and it's readable for more complicated scenarios.

```
$html = '<html><body><div class="description"><p>some text here</p></div></body></html>';
// or you could fetch external sites 
// $html = file_get_contents('http://example.com');

$doc = new DOMDocument();
// prevent parsing errors (frequent with HTML)
libxml_use_internal_errors(true);
$doc->loadHTML($html);
// enable back parsing errors as the HTML document is already parsed and stored in $doc
libxml_use_internal_errors(false);
$xpath = new DOMXpath($doc);

foreach ($xpath->query('//div[@class="description"]') as $el) {
    var_dump($el->textContent);
}

```