You have two options. The first is to return them:
function get_links($website) {
$html = file_get_html($website);
$img = $html->find('div.entry img',0)->src;
$url = $html->find('div.entry a',0)->href;
return array('img' => $img, 'url' => $url);
}
You can only return one value from a function, so you have to make an array.
The other option is to take arguments by reference:
function get_links($website, &$img, &$url) {
$html = file_get_html($website);
$img = $html->find('div.entry img',0)->src;
$url = $html->find('div.entry a',0)->href;
}
When you call this, you can then provide two values, which will contain the values:
get_links($someurl, $image, $url);
echo $image; // echoes the image source
echo $url; // echoes the url
I expect the first technique (the array) would be the simpler.
You have other options: you could make $img and $url global. This is a Bad Idea. You could also define get_links as an anonymous function and use the use keyword, but this is less useful, I think. You could also encapsulate the function in an object:
class Links {
public $url;
public $img;
function __construct($website)
$html = file_get_html($website);
$this->img = $html->find('div.entry img',0)->src;
$this->url = $html->find('div.entry a',0)->href;
}
}
// elsewhere
$links = new Links($someurl);
$links->img;
$links->url;
}