1 Attachment(s)
beginning php programmer ( Wamp , eclipse )
Hi,
I am a beginning programmer in PHP. I am using WAMP and Eclipse - PDT
I'm running a script in eclipse which attempts to download articles from articlebase.com.
The script is attached. I'm getting syntax errors which I do not understand. The entire script is included.
Code:
<?php
$category="hello ";
function get_category_links($category,$page=1)
{
$page = intval($page);
$url = “http://www.articlebase.com/”.strtolower($category).”-articles/$page/”;
$html = file_get_contents($url);
if(!$html) return false;
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$elements = $xpath->query(“//div[@class='article_row']//h3/a”);
$links = array ( );
if (!is_null($elements)) {
foreach ($elements as $element) {
$links[]=$element->getAttribute(‘href’);
}
} else {
return false;
}
array_unique($links);
return $links;
}
?>
the error a line 8 is
" Parse error: parse error in C:\wamp\www\articlebase\ab1.php on line 8 "
a screenshot of the errors is attached
Could anyone explain what the problem is.
Thanks in advance,
KC
Parse error: syntax error, unexpected T_FOR
Thanks Daniel,
that got it working. I'm now working on another function , but I'm stumped again. I'm getting a " Parse error: syntax error, unexpected T_FOR " error
My script is below
Code:
<?php
$aa = get_article("http://www.articlesbase.com/find-articles.php?q=beauty&page=1");
// echo($aa);
function get_article($url){
$html = file_get_contents($url);
if(!$html) return false;
$result = array();
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
//get title
$elements = $xpath->query("//div[@class='article_pg']//h1");
$element = $elements->item(0);
** $result['title']=strip_tags($element->nodeValue);
//get body
$elements = $xpath->query("//div[@class='article_cnt KonaBody']");
$element = $elements->item(0);
$result['body'] = $dom->saveXML($element);
//get author bio
$result['author_bio']=";
$xpath = new DOMXPath($dom);
$elements = $xpath->query("//div[@class='author_details']/p");
for ($i = 0; $i < $elements->length; $i++ ) { //$paras->length
$element = $elements->item($i);
$result['author_bio'] .= $dom->saveXml($element);
}
return $result;
}
?>
the error is at line 33 ( marked by ** )
does anyone see a problem?
Thanks again,
KC