Results 1 to 6 of 6

Thread: beginning php programmer ( Wamp , eclipse )

  1. #1
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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
    Last edited by djr33; 08-29-2010 at 09:19 PM. Reason: Fixed [/code] tag.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Those are not quotation marks, at least not the standard ones. Those are angled and different for opening and closing, like in Microsoft Word. I don't know why your program is doing this, but I highly suggest getting a better program-- there are a lot out there and many are free. You can even use notepad if you want.
    Also, the single quotes are wrong too.

    If you want to fix this, you can cut and paste these symbols from my post:
    "
    '

    Just replace all of them in your code above and it will fix that...
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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
    Last edited by djr33; 09-02-2010 at 10:29 PM. Reason: fixed [/code] tag

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    You have a lot of extra blank lines. Because of this, line 33 is not at **. Instead it is at the "for" loop, like you'd expect from the error. I don't know if all servers are configured to count like that, but it's worth knowing that your server does this if you plan to add blank lines.

    The problem is this line:
    $result['author_bio']=";

    You don't close that quote or give it any value. Fix that, and this may work, or at least you will find the next problem.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    kc11 (09-04-2010)

  6. #5
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi again,

    I am getting a " Trying to get property of non-object" error on line 27

    [CODE]

    <?php

    // $link = "artcile_base_article_link";

    // $html = file_get_contents($links);

    $aa = get_article("http://www.articlesbase.com/find-articles.php?q=beauty&page=1");

    function get_article($url){

    $html = file_get_contents($url);
    if(!$html) return false;

    echo ($html);

    $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);



    return $result;

    }

    ?>

    [CODE]

    the problem line is marked by " ** "

    Can anyone explain this?

    thanks,

    KC

  7. #6
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    $element does not become an object when it is set to a value of an object, if item(0) does not return an object, then maybe try:
    PHP Code:
    $result['title']= strip_tags($elements->item(0)); 
    I do not know the class structure that you are using, so this is a guess.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •