The Following code is checking for links within a page and then trying to process those links and check if they work or not, by returning a header code. I basically need to use the returned value $links of the first function in the second one. is it possible?
here is my code
function checkPage ($content){
$textLen = strlen($content);
$links = array ();
if ( $textLen > 5){
$startPos = 0;
$valid = true;
while ($valid){
$spos = strpos($content,'<a ',$startPos);
if ($spos < $startPos) $valid = false;
$spos = strpos($content,'href',$spos);
$spos = strpos($content,'"',$spos)+1;
$epos = strpos($content,'"',$spos);
$startPos = $epos;
$link = substr($content,$spos,$epos-$spos);
if (strpos($link,'https://') !== false) $links[] = $link;
if (strpos($link,'http://') !== false) $links[] = $link;
}
}
return **$links**;
};
print_r(checkPage($content));
foreach ($links as &$link ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$headers = curl_getinfo($ch);
if(curl_error($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $link." returns code ".$headers['http_code']."<br />";
};
return **$links**;? Do you mean that you simply want to store the value from thecheckPage()function? This is PHP101...$links = checkPage($content);.$links = checkPage($content);? That looks to be missing from your code, but that's very basic PHP considering what you already have.