Jump to content

Graxeon

Members
  • Posts

    260
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Graxeon's Achievements

Member

Member (2/5)

0

Reputation

  1. Hmm...tried messing with it. Can't seem to get it to echo anything :/ I also tried echoing $hrefs directly. Blank page <?php /* domdochtml.html: <table id="myTable"> <tr> <td class="gold"><a href="http://google.com"></td> <td class="black"><a href="http://youtube.com"></td> </tr> </table> */ // Variable value will be "http://youtube.com" $html = file_get_contents('http://fixitplease.ulmb.com/domdochtml.html'); $doc = new DOMDocument(); @$doc -> loadHTML($html); $xp = new DOMXPath($doc); $hrefs = $xp -> evaluate("//table[@id = 'myTable']//td[@class = 'black']/@href") -> item(0) -> nodeValue; /* I've also tried echoing $hrefs: echo $hrefs; (doesn't return anything) */ foreach ($hrefs as $href) { $href = $href -> nodeValue; echo "{$href}<br />"; } ?>
  2. Ok...I understand that. But the <a> tags depend on the <td>'s classes (which are f or m). I tried playing with it: $hrefs = $xp -> evaluate('//a["class" = "f"]/@td'); $hrefs = $xp -> evaluate('//a["class" = "f"]/@href'); But it didn't return anything. But to make it less complex, is there a section in the manual that gives an example to search for "http://main"? Where "main" could be any value and it would output the value of "a" (which would be "Page #").
  3. Interesting... It managed to pull out all of the URLs. But I have to search Google for a few hours to figure out what filters/protocol DOMDocument uses . Cause for example: //a/@href -is searching for href's? I understand the rest of the script. But I have no idea how that filter/parse term is being used. I'm here: http://php.net/manual/en/class.domdocument.php Can someone point me into the right section? xD
  4. I'm trying to parse 2 things. 1. Specific TD tags from a table. 2. Specific URLs from an HTML page. Here's part of the data I'm trying to parse: <tr> <td class="f"> <a href="http://main1.site.com/x.html">Page 1</a> </td> <td>1572</td> <td class="a">Type: F</td> <td><img src="http://site.com/image.gif" title="N" alt="N" /></td> <td class="f">F</td> </tr> <tr class="x"> <td class="m"> <a href="http://main2.site.com/x.html">Page 2</a> </td> <td>1771</td> <td class="a">Type: M</td> Here's the parser that I'm working with: <?php $html = file_get_contents('http://www.website.com/page.html'); // use this to only match "td" tags #preg_match_all ( "/(<(td)>)([^<]*)(<\/\\2>)/", $html, $matches ); // use this to match any tags #preg_match_all("/(<([\w]+)[^>]*>)([^<]*)(<\/\\2>)/", $html, $matches); //use this to match URLs #preg_match_all ( "/http:\/\/[a-z0-9A-Z.]+(?(?=[\/])(.*))/", $html, $matches ); //use this to match URLs #preg_match_all ( "/<a href=\"([^\"]*)\">(.*)<\/a>/iU", $html, $matches ); preg_match_all ( "/<a href=\"([^\"]*)\">(.*)<\/a>/iU", $html, $matches ); for ( $i=0; $i< count($matches[0]); $i++) { echo "matched: " . $matches[0][$i] . "\n<br>"; echo "part 1: " . $matches[1][$i] . "\n<br>"; echo "part 2: " . $matches[2][$i] . "\n<br>"; echo "part 3: " . $matches[3][$i] . "\n<br>"; echo "part 4: " . $matches[4][$i] . "\n\n<br>"; } ?> What I'm trying to output is: <a href="http://main1.site.com/x.html">Page 1</a> Hits: 1572 <a href="http://main2.site.com/x.html">Page 2</a> Hits: 1771 ...for the entire table What I've managed to get out of it so far are the "Hits" with the "td" snippet. What I can't figure out is how to extra the full: <a href="http://main.site.com/p#.html">Page #</a> So my question is how can I make it look for just "<a href="http://main#.......">Page #</a>"? Currently it looks for every URL, which is not what I need.
  5. Graxeon

    $_GET?

    Does anyone know how to retrieve the http header information in an array or similar format?
  6. Graxeon

    $_GET?

    Ok, but would you know anything about this?: Go to: http://www.softswot.com/http-header.php?#viewer Type in this URL and click Send Request: http://tiny.cc/7n0i9lvimd (this redirects you to Google.com) The "http-header.php" will display this info: Received Response HTTP/1.1 301 Moved Permanently Server: nginx/0.7.65 Date: Mon, 04 Oct 2010 02:54:43 GMT Content-Type: text/html Connection: close X-Powered-By: PHP/5.3.2 Set-Cookie: session= (alphanumerical data here); expires=Mon, 04-Oct-2010 05:54:43 GMT; path=/; domain=.tiny.cc Set-Cookie: tycc7n0i9lvimd=1286160883; expires=Thu, 04-Oct-2012 02:54:43 GMT Location: http://www.google.com How can I do the same thing on my "display.php" file? (or at least just show the "Location" information)
  7. Graxeon

    $_GET?

    I have "mysite.com/display.php" That file goes to this URL: site.com/user/redirect Since that URL redirects to "site.com/user.php?level=site.com/123.php?hp=1"...I want "display.php" to only redirect to "site.com/123.php?=1" **Note that display.php and the redirecting URL are on different hosts/servers (hence why $_GET doesn't seem the way to go for me) edit: if I'm not explaining it too well, can you at least tell me how I can request HTTP Header information from any website like this page does: http://www.softswot.com/http-header.php?#viewer (type in any URL that redirects in the box first then click Send Request). I'd like the "Location" info echoed. That, or how can I parse the URL so that it gives me the URL once it has redirected me?
  8. Graxeon

    $_GET?

    I think has to do with http headers. How can I request http header information with PHP? @coupe: but that's only if the request was sent on the current page. My page is "mysite.com/display.php". And what "display.php" is supposed to do is what I described in my first post. So that wouldn't necessarily work.
  9. Graxeon

    $_GET?

    I have a link (http://site.com/user/redirect). This link directs me to "site.com/user.php?level=site.com/123.php?hp=1" How can I echo just "site.com/123.php?hp=1"? I know how to use $_GET but I don't know how I can apply it to this.
  10. I'm trying to build a calculator for a game...but I'm stuck on the extracting part. I don't really know how to go about it (so if you know of a tutorial/handbook please link), but how I would I extract this data: //data to extract $name = "Robin hood hat" $currentprice = "3.3m" $change = "+11.5k" //display echo $name echo $currentprice echo $change from: http://itemdb-rs.runescape.com/results.ws?query=robin hood hat I know about get_file_contents and doing it line by line...but that turns into a pain with many things to grab. Is there a way of grabbing it by table definition similarly to the way Google Docs does? Google Docs link format: =Index(ImportHtml("http://itemdb-rs.runescape.com/results.ws?query=Robin hood hat", "table", 2),2,4) This goes to the 2nd table, 2nd row, and 4th column for the "Change" data.
  11. So does anyone know of a method to extract the information similar to the way I describe in the last post? (through tables and not specific lines from get_file_contents)
  12. Never mind about the converting question. I'm still clueless on the extracting question xD Btw...here's how I did the converting (yes, it's lengthy and newbie...but it works for what I need since all values go to the tenths): if (strpos($source, 'k') !== false) { if (strpos($source, '.') !== false) { $source = preg_replace("/[^0-9]/", "", $source); echo $source*100; } else { $source = preg_replace("/[^0-9]/", "", $source); echo $source*1000; } } else { if (strpos($source, 'm') !== false) { if (strpos($source, '.') !== false) { $source = preg_replace("/[^0-9]/", "", $source); echo $source*100000; } else { $source = preg_replace("/[^0-9]/", "", $source); echo $source*1000000; } } else { $source = preg_replace("/[^0-9]/", "", $source); echo $source; } } I think you can just put the preg_replace at the top of the code and it'll do the same thing (so it won't be repetitive). I just kept it cause I might need the original values later on.
  13. I just found a problem with the preg_replace. I need to convert all values that higher than 999 (for example, +11.5k needs to convert to 11500). I would do this by just multiplying the source (or $change in your code) by 1000. But how would I distinguish between a value that has a "k" or "m" at the end (higher than 999) and one that doesn't (lower than 1000)?
  14. Well...thats good except that this would have to be done for over 100 different pages. How would I make it more dynamic? I know google docs does it by table like this: =Index(ImportHtml("http://itemdb-rs.runescape.com/results.ws?query=Robin Hood Hat", "table", 2),2,4) (that's for the "Change") Is there something similar to this in PHP?
  15. I know about get_file_contents but I don't know how to specify that exact data
×
×
  • 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.