Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. I might as well give you the whole thing .. keep in mind that this may break each time google subtly alters their SERP format. <?php function fetch_google_results($content) { $parser = new HtmlParser($content); $display = false; $rank = 0; $urls = array(); while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'blockquote' && $parser->iNodeAttributes['class'] == 'g') { /* Find the end of the blockquote */ while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ENDELEMENT && $parser->iNodeName == 'blockquote') { break; } } } if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'div' && $parser->iNodeAttributes['class'] == 'g') { while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'a') { break; } }; $url = $parser->iNodeAttributes['href']; if ($url == '') continue; $rank++; $urls[$rank]['url'] = $url; // print "$rank: $url\n"; /* Title can contain bold tags. Identify it by anchor tags */ $title = ''; while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ENDELEMENT && $parser->iNodeName == 'a') { break; } if ($parser->iNodeType == NODE_TYPE_TEXT) { $title .= $parser->iNodeValue; } } $urls[$rank]['title'] = $title; /* Fetch the extract from the page itself */ /* We stop when we find a <td> */ while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'td') { break; } } $parser->parse(); /* <font size="-1"> */ $description = ''; while ($parser->parse()) { /* Ends with a span tag */ if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'span') { break; } if ($parser->iNodeType == NODE_TYPE_TEXT) { $description .= $parser->iNodeValue; } } $urls[$rank]['description'] = $description; } } return $urls; }
  2. Try $ProImg2[] = $row2['name']; in your loop
  3. You can pass the mysql link identifier as an argument to mysql_query()
  4. Ok. What's wrong with the code you're using now?
  5. FYI, this extension is now under development.  Here is the underlying data structure: [code=php:0]typedef enum _c_array_entry_types {         C_ARRAY_STRING,         C_ARRAY_INTEGER,         C_ARRAY_FLOAT,         C_ARRAY_DOUBLE } c_array_entry_type; typedef struct {         char *name;  /* Name of element */         c_array_entry_type type;    /* Type of element */         size_t size; /* Size of element */         int offset;  /* Offset of element from start of struct */ } c_array_entry; typedef struct {         int len;    /* Length of array */         int size;  /* Size of array entry */         int entries_len; /* Length of array description */         c_array_entry *entries; /* Array description */         char *data; /* Actual array data is stored here */ } c_array;[/code] I haven't optimized either of these for size as there will only be a few of them in existence for each array.  The actual data will all be stored in char *data, and will be packed tightly.  I'll probably add data types less than one word once i've sorted out alignment issues.
  6. You might be interested in the ELO rating system. It's used in chess and also in some online game rankings. The basic idea is that when you play a match, your ranking changes depending on the result of the game and the ranking of your opponent. People who win games against strong players will get high rankings, but people who win the same number of games against weaker players will still get low rankings. You can calculate this in retrospect if you have a full history of games played. For your situation, the rankings of your 100/25, 20/0 and 30/20 players would depend more on who they played than the win/loss ratios, which on their own can be quite misleading. A 30/20 score against the top players should be ranked higher than a 20/0 score against the weakest ones.
  7. I use an html parser to process the google SERP and extract the link data.
  8. Try setting the "alt" attribute as well as title. You might also want to check out overlib for more sophisticated rollover popups. Hmm, do you want an image appearing in the rollover popup? Or just text?
  9. That's a "newline" character. It shows up in echo as an actual new line, so that's why you don't see it. The easiest way to deal with it is to use trim() on your data from fread(). trim() will remove spaces, newlines and some other invisible stuff from the start and end.
  10. No, unfortunately. You will need to do the join yourself in php.
  11. Try adding this line just before your "if" statement: print "Logname: " . urlencode($_SESSION['logname']) . ", thedata: " . urlencode($theData); exit(0); Do they match exactly?
  12. Can you explain a bit better what you want? Which line do you want to pull out? Better still, tell us what output you want. preg_grep() and preg_match() work exactly the same way. You might want to try again with preg_match using the regexp that effigy provided. preg_match() checks one string only, and is usually used inside an "if" condition. preg_grep() checks an array of strings, and gives you an array of matching strings.
  13. mdb2 is an abstraction layer, meaning the same code will be more easily ported to other databases. Mysqli is an interface directly to mysql only, so porting will be more difficult. There's probably more mysql specific features in mysqli too.. that's a rule of thumb when it comes to abstraction.
  14. My company hosts around 1 million sites on one box on one ip address. Around 90% of those sites get 0-1 hits per day though. Basically there is no limit to the number of sites, there is only a limit to total traffic.
  15. A mysql result consists of rows and columns. For example id num 1 10 2 50 mysql_fetch_array() fetches one row only! It's an "array" because each array element is one column. So you must call mysql_fetch_array() many times, usually like this: while ($row2 = mysql_fetch_arrow($result2)) { print "id: {$row2['id']}, num: {$row['num']}\n"; }
  16. You can get a call tree from an actual run of your script using apd. But I take it you want something that works from the source? If you find one, I would be very interested
  17. It's time you got familiar with foreach! $matches = preg_grep('/(?:jpg)|(?:gif)/', $content); $non_matches = preg_grep('/(?:jpg)|(?:gif)/', $content, PREG_GREP_INVERT); foreach ($matches as $image) { print $image; } foreach ($non_matches as $url) { $gcontent = file_get_contents($url); echo $gcontent; } The difference with using preg_match() is that you will get the items in the original order. With preg_grep(), you'll get all the images first then the urls second (or the other way around)
  18. If you really want to use preg_grep(): $matches = preg_grep('/(?:jpe?g|gif)$/', $content); $non_matches = preg_grep('/(?:jpe?g|gif)$/', $content, PREG_GREP_INVERT);
  19. Because the code the OP is dealing with uses sprintf Not much point teaching him how to use php style substitution when he's modifying code that uses sprintf. Padgoi, I think you've got 2 choices here: 1. Learn enough php to do your own modification 2. Post on the freelancing forum and get someone to do it for you
  20. Actually, preg_grep() is the wrong function for what you want to do, because it does not allow an "else". Instead you should use preg_match like this: foreach ($content as $c) { if (preg_match('/(?:jpe?g|gif)$/', $c)) { echo $c; } else { $gcontent = file_get_contents($c); echo $gcontent; } }
  21. Thanks for pointing out my regexp mistake! As for why the "else" is not working, try running this code on its own: echo file_get_contents("http://www.website.com/textfile.txt"); That will tell you if the link actually works and can be accessed with file_get_contents() in the first place.
  22. I looked at the script.. it's just a front end to mysql's OPTIMIZE TABLE.
  23. I think jitesh misunderstood your question. To redirect via headers: header("Location: http://site.com/page.php"); exit(0); or header("Location: /page.php"); exit(0); The exit isn't necessary, but there's usually nothing much worth doing if you're going to do an immediate redirect. This redirect occurs at the HTTP level, which means the browser will never display the page. Instead it will do the redirect before displaying anything. Meta refresh will display the page and THEN redirect.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.