You better use DOMDocument. It has many and useful functions to find links, textContent, manipulate dom and more.
For example to get the urls of images:
$dom = new DOMDocument;
@$dom->loadHTML($response); //I assume that you're reading/curling pages
foreach ($dom->getElementsByTagName('img') as $node) {
if ($node->hasAttribute('src')) {
$url = $node->getAttribute('src');
//Also you can do some regex here to validate urls
//and bypass those like "<%= avatar %>"
echo $url,'<br>';
}
}
These methods can also be very usefull
$node->nodeValue //To get the textContent of the node
$node->childNodes //To get the children of the node. It will return a nodelist object
//as getElementsByTagName('img')
$node->nodeType // Some nodes returned when calling childNodes are textnodes
//so they can be bypassed with a conditional:
//if( $node->nodeType == 1){//It's an element node}
$nodes->length // length of a nodelist object
$nodes->item(1) // 2nd node of a nodelist