Witam mam taki problem i nie mogę sobie poradzić. Mam formularz który sprawdza pozycje przypisanych fraz w google i po ich sprawdzeniu wypluwa na stronę wynik ja ten wynik chcę przechwycić i zapisać do pliku, i właśnie tu tkwi problem. Nie wiem dlaczego ale nie bardzo chce mi zapisać wynik mimo ze plik .txt zostaje nadpisany ale pozostaje pusty, proszę o pomoc i wskazówki. Najważniejsza jest końcówka kodu jest wyboldowana. Interesuje mnie zapis pozycji jedna pod drugą a to cały kod:
<html>
<head>
<title>Sprawdzanie pozycji</title>
</head>
<style type="text/css">
body{background:#cccccc; text-align:center; margin:20px; font-family:arial; font-size:12px}
td{font-family:arial; font-size:12px}
input{width:300px}
textarea{width:300px}
</style>
<body>
<form action="" method="POST">
Keywords:
<textarea rows="15" cols="50" type="text" name="keywords">
<? print $_POST['keywords']?
$_POST['keywords']:"Enter keywords each from new line"; ?></textarea>
Website URL (without http://)
<input type="text" name="site" value="
<? print $_POST['site']?
$_POST['site']:"www."; ?>">
<input type="submit" name="zapisz" value="Check">
</form>
<?
function getGoogleResults($query, $start) {
$googleurl="http://www.google.pl/";
$googlesearch = "search?q=$sesse&hl=pl&start=$start&sa=N";
$pagesource = curlGetPage($googleurl.$googlesearch, "http://www.google.pl/");
$urls = getTags($pagesource, "<li class=g><h3 class=r>", "</a>");
for($i = 0; $i < sizeof($urls); $i++) { $href = "";
$anchors = getTags($urls[$i], "<a", ">");
$href = getTagField($anchors[0], "href=");
$urlslist[$i] = $href;
}
return $urlslist;
}
function curlGetPage($url, $referer) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS["agent"]);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
if($referer != "") {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
$html = curl_exec($ch);
if(curl_errno($ch)) {
$html = "";
}
curl_close ($ch);
return $html;
}
function getTags($source, $start, $end) {
$tmp = $source;
for($i = 0; strlen($tmp) > 0; $i++) { if(($postagst = strpos($tmp, $start)) == false) break;
$tmp = substr($tmp, $postagst); $postagend = strpos($tmp, $end); if($postagend > 0)
else {
$tags[$i] = $tmp;
}
}
return $tags;
}
function getTagField($tag, $fieldname) {
$field = "";
if(($pos = strpos($ttag, $fieldname)) > 0
) { if($tmpfield[0] == '"' || $tmpfield[0] == "'") {
if($tmpfield[0] == '"') {
$tmpfield = substr($tmpfield, 1
); }
if($tmpfield[0] == "'") {
$tmpfield = substr($tmpfield, 1
); }
}
else {
if(strpos($tmpfield, ' ') > 0
) else
$field = $tmpfield;
}
}
return $field;
}
if ($_POST['keywords']) {
$keywords = $_POST['keywords'];
$site = $_POST['site'];
print "<table align=\"center\" border=\"1\"><tr><td><b>Keyword</b></td><td><b>Position</b></td><td><b>Page in SERP</b></td></tr>"; for ($i1=0; $i1<count($keyword); $i1++) {
for($ses = 0; $ses < 100; $ses = $ses + 10) {
$googleurlslist = getGoogleResults($keyword[$i1], $ses);
for($i = 0; $i < sizeof($urlslist); $i++) { if (!strpos($urlslist[$i], "interstitial")) { }
else
{
$without = str_replace("/interstitial?url=", "", $urlslist[$i]); }
if ($googl['host']==$site || $googl['host']==$siteurl) {
$siteposit = $ses + $i + 1;
echo "<tr><td>".$keyword[$i1]."</td><td>".$siteposit."</td><td>".$urlslist[$i]."</td></tr>";
break 2;
}
else
{
if ($ses==40 && $i==9) {
echo "<tr><td>".$keyword[$i1]."</td><td>Brak w pierwszej 100</td><td>No</td></tr>"; }
}
}
}
}
[b]{
$tekst = $_POST['$siteposit'];
$otworz = fopen("test.txt", "w+"); }[/b]
}
?>
<br
</body>
</html>