Hi Everyone,
It has been quite a while since I made a post here but the last time I got such great help that I thought I would try you all again to see who could help me overcome my stupdity.
Let me begin with the fact that I am a newbie and this is only like the 3rd PHP script that I have written.
In any case, here is what I am trying to do.
I want to grab my Ebay feedback rating from the ebay web site and display it on my own page.
The page that I am getting the information from is:
http://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&userid=thescrapbookfairy&ftab=AllFeedback&myworld=true
You can do a "view source" on that page to see all of the code.
About halfway done the page (in code view) you will see a basic HTML table. Here it is:
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="fbsBigLabel">
<td nowrap="nowrap">Feedback Score:</td>
<td><b>657
</b></td>
</tr>
<tr class="fbsBigLabel">
<td nowrap="nowrap">Positive Feedback:</td>
<td><b>99.8%</b></td>
</tr>
<tr>
<td colspan="2" class=fbsBufferRow> </td>
</tr>
<tr>
<td nowrap="nowrap">Members who left a positive:</td>
<td>658</td>
</tr>
<tr>
<td nowrap="nowrap">Members who left a negative:</td>
<td>1</td>
</tr>
<tr>
<td colspan="2" class=fbsBufferRow> </td>
</tr>
<tr>
<td nowrap="nowrap">All positive Feedback:</td>
<td>1044</td>
</tr>
<tr><td colspan="2" class=fbsBufferRow> </td></tr><tr><td nowrap="nowrap" colspan="2"><a href="http://pages.ebay.com/help/feedback/evaluating-feedback.html">Find out what these numbers mean</a></td></tr>
</table>
I am attempting to grab this table, stip all info except for the numerical values, turn them into variables then display it into this table that will be on my website:
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" CLASS="feedbackTable">
<tr>
<TD CLASS="feedbackTableTitle">Feedback Score:</TD>
<td CLASS="feedbackTableValue"><b>$fbScore</b></td>
</tr>
<tr>
<td CLASS="feedbackTableTitle">Positive Feedback:</td>
<td CLASS="feedbackTableValue"><b>$fbPFPct</b></td>
</tr>
<tr>
<td colspan="2" CLASS="feedbackTableBlankRow"> </td>
</tr>
<tr>
<td CLASS="feedbackTableTitle">Members who left a positive:</td>
<td CLASS="feedbackTableValue">$totalPositive</td>
</tr>
<tr>
<td CLASS="feedbackTableTitle">Members who left a negative:</td>
<td>$totalNegavtive</td>
</tr>
<tr>
<td colspan="2" CLASS="feedbackTableBlankRow"> </td>
</tr>
<tr>
<td CLASS="feedbackTableTitle">All positive Feedback:</td>
<td CLASS="feedbackTableValue">$allPositive</td>
</tr>
<tr>
<td colspan="2"CLASS="feedbackTableBlankRow"> </td>
</tr>
<tr>
<td colspan="2"><a href="http://pages.ebay.com/help/feedback/evaluating-feedback.html">Find out what these numbers mean</a></td>
</tr>
</table>
Here is the PHP script that I have written to accomplish this task:
<!-- Begin PHP feeback Script include file -->
<?php
##########################################
# php eBay Feedback Grabber 1.0
# Grab and Display your eBay Feedback Information on your website!
# This software is open source. Feel free to use it anyway you like.
# Just keep this author informaton included in the script:
# Original Author: Rick Pugh
# Original Author eMail: rickpugh(at)hotmail(dot)com
# Original Author website: http://www.thescrapfairy.com
##########################################
//-----------------------------------------------------------------
// Script and CSS Values:
//
// Your Ebay Member Name - Must be correct!
$ebayid = "thescrapbookfairy";
//Script builds a basic table with CSS classes for formatting. Just include these css //classes in the Style Sheet for the page that is displaying the results of the script
// feedbackTable - Class for the overall table
// feedbackTableTitle - Class for table cells that hold the title of values to be displayed (ie. Feedback Score, etc..)
// feedbackTableValue - Class for the actual values returned by the script
// feedbackTableBlankRow - class for black table row used for formatting
//-----------------------------------------------------------------
// Nothing below here should need editing.
//
// Build the URL where we will get the data. This url uses a ebayID variable you enterd above
$URL = "http://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&userid=$ebayid&ftab=AllFeedback&myworld=true";
// Where do we start grabbing on this page?
$Start = "<tr class=\"fbsBigLabel\">";
// Where do we stop grabbing on the page?
$GrabEnd = "<a href=\"http://pages.ebay.com/help/feedback/evaluating-feedback.html\">";
// Create the cache file
$file = fopen("$URL", "r");
// Read the page and store it into memory so we can parse and use it
if (!function_exists('file_get_contents')) {
$r = fread($file, 80000);
}
else {
$r = file_get_contents($URL);
}
// Grab the data we want by getting everything between start and end and get rid of
// everything else we call what we have left $content
$stuff = eregi("$Start(.*)$GrabEnd", $r, $content);
// Get rid of everything between start and stop except for the feedback values that we need.
$content[1] = ereg_replace("<tr class=\"fbsBigLabel\"><td nowrap=\"nowrap\">Feedback Score:</td><td><b>","",$content[1]);
$content[1] = ereg_replace("</b></td></tr><tr class=\"fbsBigLabel\"><td nowrap=\"nowrap\">Positive Feedback:</td><td><b>","",$content[1]);
$content[1] = ereg_replace("%</b></td></tr><tr><td colspan=\"2\" class=fbsBufferRow> </td></tr><tr><td nowrap=\"nowrap\">Members who left a positive:</td><td>","",$content[1]);
$content[1] = ereg_replace("</td></tr><tr><td nowrap=\"nowrap\">Members who left a negative:</td><td>", "", $content[1]);
$content[1] = ereg_replace("</td></tr><tr><td colspan=\"2\" class=fbsBufferRow> </td></tr><tr><td nowrap=\"nowrap\">All positive Feedback:</td><td>", "", $content[1]);
$content[1] = ereg_replace("</td></tr><tr><td colspan=\"2\" class=fbsBufferRow> </td></tr><tr><td nowrap=\"nowrap\" colspan=\"2\">", "",$content[1]);
// Line used during debug. Comment out otherwise. If you uncomment this it will print the items in the array called $content on the page so that you can make sure everything works up to the point.
//echo "<hr><br /><br />$content[1]<br /><br /> <hr>";
// Now we have the feedback values in an array called "$content" so we can get rid of the file in memory. Very Important that this occurs!
fclose($file);
$stuff = $content[1];
// break each value in the array into its own line.
$items = explode("[LINES]",$stuff);
// Count the items
// Loop through our lines
foreach ($items as $listing) {
echo "$listing";
// Break apart each line into individual items and assign them a variable name
list($fbScore,$fbPFPct,$totalPositive,$totalNegavtive,$allPositive ) = explode("[ITEMS]",$listing);
// Make sure we have content to print out and print it
echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" CLASS=\"feedbackTable\">
<tr>
<TD CLASS=\"feedbackTableTitle\">1 Feedback Score:</TD>
<td CLASS=\"feedbackTableValue\">$fbScore</td>
</tr>
<tr>
<td CLASS=\"feedbackTableTitle\">2 Positive Feedback:</td>
<td CLASS=\"feedbackTableValue\"><b>$fbPFPct</b></td>
</tr>
<tr>
<td colspan=\"2\" CLASS=\"feedbackTableBlankRow\"> </td>
</tr>
<tr>
<td CLASS=\"feedbackTableTitle\">3 Members who left a positive:</td>
<td CLASS=\"feedbackTableValue\">$totalPositive</td>
</tr>
<tr>
<td CLASS=\"feedbackTableTitle\">4 Members who left a negative:</td>
<td>$totalNegavtive</td>
</tr>
<tr>
<td colspan=\"2\" CLASS=\"feedbackTableBlankRow\"> </td>
</tr>
<tr>
<td CLASS=\"feedbackTableTitle\">5 All positive Feedback:</td>
<td CLASS=\"feedbackTableValue\">$allPositive</td>
</tr>
<tr>
<td colspan=\"2\"CLASS=\"feedbackTableBlankRow\"> </td>
</tr>
<tr>
<td colspan=\"2\"><a href=\"http://pages.ebay.com/help/feedback/evaluating-feedback.html\">Find out what these numbers mean</a></td>
</tr>
</table>\n";
}
?>
<!-- End PHP feeback Script -->
The problem that I am having is that it isn't stipping the HTML or data that I want correctly and it returns everything in the first array value ($fbScore)
I know this is probably a very simple thing but I have been here working on this for six hours and haven't had any luck.
Any help would be much appreciated.