Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    This will eventually go into tutorials, but I thought I post it here first just for the fun of it.

    If you go to Craig's List and enter your area, and search for something ... you'll get your search results page. Now, in the bottom right hand corner, you'll see an RSS link. Click on that and look at the URL on the browser address box. That URL is their dynamic RSS feed URL for your search. It contains your area, the section of CL that you searched, and your search target.

    Below is a PHP script that reads the RSS feed and displays the data. This can be used to display any particular CL feed that you wish ... perhaps on your website, or a CRON job that does a query every hour and notifies you if any new items were added for that section of CL. Essentially, you could create a snipe script that lets you know right away if someone posts an item you're looking for.

    I created a form for testing ... where I can enter my search target and a couple of options. The "narrow" option puts quotes around my target string. It seems to yield more specific results. My area is "minneapolis", so I've already hard-coded that into the RSS feed URL. In the craigslist.php script, you'll see my comments on changing that URL to match your area. Essentially, you'll copy your own CL feed URL into the script.

    Here is the form ...
    PHP Code:

    <html>
        <
    body  OnLoad="document.myform.target.focus();">
        <
    form name="myform" method="post" action="craigslist.php">
        
    Enter Search Term:  <input type="text" name="target" value="" style="width:350px;"> <br />
        <
    input type="checkbox" name="desc"> Include Description<br />
        <
    input type="checkbox" name="narrow" checked="checked"Multiple words searched literally.<br /><br />
        <
    input type="submit" name="submit" value="Submit">
        </
    form>
        <
    br /><br />
        </
    body>
    </
    html

    Here is the PHP script called "craigslist.php" ...
    PHP Code:

    <?php  

    // Get target
    $search="";
    if(isset(
    $_POST['target'])){
    $search=$_POST['target'];
    $search str_replace(" ","+",$search);
    $search str_replace("&","",$search);
    }

    if(isset(
    $_POST['narrow'])){
    $search="\"".$search."\"";
    }

    // Put your own CL feed URL on the line below, so it matches your area.
    // Also, note where the $search string is placed in the URL.
    // If you do special searches, like max and min prices, those fields will also appear in your RSS feed URL
    // Use PHP variables for any of the CL search properties.

    $feed_url "http://minneapolis.craigslist.org/search/?areaID=19&catAbb=sss&query=".$search."&format=rss";

    # INITIATE CURL. 
    $curl curl_init(); 

    # CURL SETTINGS. 
    curl_setopt($curlCURLOPT_URL,"$feed_url"); 
    curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0); 

    # GRAB THE XML FILE. 
    $data curl_exec($curl); 

    curl_close($curl); 

    $doc = new SimpleXmlElement($dataLIBXML_NOCDATA);

    if(isset(
    $doc->channel)){
        
    parseCraigslist($doc);
    }

    function 
    parseCraigslist($xml){
        echo 
    "<strong>".$xml->title."</strong>";
        
    $cnt count($xml->item);
        for(
    $i=0$i<$cnt$i++)
        {
        
    $title     $xml->item[$i]->title;
        
    $url     $xml->item[$i]->link;
        
    $desc $xml->item[$i]->description;
     
     
    //Use that namespace
      
    $dc $xml->item[$i]->children("http://purl.org/dc/elements/1.1/");
      
    $date $dc->date;
      
    $part explode("T",$date);
         if(isset(
    $_POST['desc'])){
         
    $list[] = $part[0]." | <a href='".$url."'>".$title."</a><br />".$desc."<br /><hr><br />";
         }
         else{
         
    $list[] = $part[0]." | <a href='".$url."'>".$title."</a><br />";
         }
        }

    if(
    count($list)>0){    
        
    rsort($list);
        foreach(
    $list as $row){
        echo 
    $row;
        }
    }
    else{
    echo 
    "No items found.";
    }
    }

    ?>

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Nifty
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Way cool - I'm going to try it out when I have some time!
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!


Remove Ads

Posting Permissions

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

Search tags for this page

curl into craigslist
,

how to display a craigslist feed php

,
mashup rss feed with php
,
php feed mashup
Click on a term to search for related topics.
All times are GMT -6. The time now is 01:24 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com