I’m using simple html DOM and extracting two links from website.
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;}
how do I use $img and $url after I run function get_links?
You have two options. The first is to return them:
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:
When you call this, you can then provide two values, which will contain the values:
I expect the first technique (the array) would be the simpler.
You have other options: you could make
$imgand$urlglobal. This is a Bad Idea. You could also defineget_linksas an anonymous function and use theusekeyword, but this is less useful, I think. You could also encapsulate the function in an object: