Question: > 
> **Possible Duplicate:**  
> 
> [How to parse and process HTML with PHP?](https://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php) 
> 
> 
> 

I am selecting a column from a mySQL table which has a value something like this:

```
<div class="article news group">
    <p class="news_info">18/10/12</p>
    <h2>Hello world!</h2>
    <p>ertwrt aerteartert</p>
    <p>ertaertert</p>
    <p>waertwertwertwaertweart</p>
</div>

```

I now need to only get the 3 p tags from this - so returning:

```
    <p>ertwrt aerteartert</p>
    <p>ertaertert</p>
    <p>waertwertwertwaertweart</p>

```

Is there an easy way to do this with php or will I need to use jQuery to remove the unwanted code.

Either way, any ideas how I would do it?

Answer: 
Using PHP

```
$html = '<div class="article news group">
    <p class="news_info">18/10/12</p>
    <h2>Hello world!</h2>
    <p>ertwrt aerteartert</p>
    <p>ertaertert</p>
    <p>waertwertwertwaertweart</p>
</div>';

preg_match_all('~(<p>.+?</p>)~', $html, $match);

echo implode("\n", $match[1]);

```
This may be help for your needs : <http://api.jquery.com/siblings/>