I have the following PHP code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mencari link dari hasil google search dan menyimpan ke file</title>
</head>
<body>
<form method="post" action="">
<input name="wewewe" >
<div id="submit">
<input type="submit" />
</div>
</form>
<?php
require_once('simple_html_dom.php');
$myfile = fopen("blogspot.txt", "a+") or die("Unable to open file!");
$url = $_POST['wewewe'];
$html = file_get_html($url);
$linkObjs = $html->find('li.sidebar-item a');
foreach ($linkObjs as $linkObj) {
$link = trim($linkObj->href);
// if it is not a direct link but url reference found inside it, then extract
if (!preg_match('/^https?/', $link) && preg_match('/q=(.+)&sa=/U', $link, $matches) && preg_match('/^https?/', $matches[1])) {
$link = $matches[1];
} else if (!preg_match('/^https?/', $link)) { // skip if it is not a valid link
continue;
}
echo "<a href='". $link ."'>$link</a>". '</p>' ;
fwrite ($myfile, "<a href='". $link ."'>$link</a>". '</p>'."
") ;
}
fclose($myfile);
?>
</body>
</html>
I'm using:
- Xampp OK
- Simplehtmldom1_5 OK
- Imacros OK
I'm also having another script like this but no needed Imacros but the file is still empty. Can anyone help?