
Graxeon
Members-
Posts
260 -
Joined
-
Last visited
Everything posted by Graxeon
-
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 />"; } ?>
-
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 #").
-
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
-
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.
-
Does anyone know how to retrieve the http header information in an array or similar format?
-
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)
-
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?
-
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.
-
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.
-
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.
-
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)
-
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.
-
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)?
-
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?
-
I know about get_file_contents but I don't know how to specify that exact data
-
hehe...yeah I just found something similar to that. Thank you though, yours is cleaner I'm still wondering about the extraction part, though
-
I'm trying to build a calculator for a game...but I'm stuck on the extracting part. I don't really know what it's called (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 And a small question: how would I convert "+11.5k" into "11500" (1k = 1,000)? The * multiplies it but how do I check for and remove the "+" and "k"?
-
I know, but that would mean that each youtube link is split into different tracks. I need a way of putting them into 1.
-
There are some video tutorials on YouTube that I'm trying to play in my JW FLV player. However, the videos are split into parts and I'd like for those parts to play right after one another. I know I can make another "track item" in my XML playlist...but how can I send more than 1 URL to my FLV player so that it just plays them back-to-back once the previous one(s) finishes? So let's say I have this: <track> <title>Tutorial 1</title> <location>http://www.youtube.com/watch?v=GOfhmzNLWzY</location> <annotation>Introduction</annotation> <info></info> <meta rel='type'>video</meta> </track> <track> <title>Tutorial 2</title> <location>http://www.youtube.com/watch?v=eUsuuxo3nYo</location> <annotation>Part 1</annotation> <info></info> <meta rel='type'>video</meta> </track> <track> <title>Tutorial 2</title> <location>http://www.youtube.com/watch?v=ouumT9LoMLk</location> <annotation>Part 2</annotation> <info></info> <meta rel='type'>video</meta> </track> <track> <title>Tutorial 2</title> <location>http://www.youtube.com/watch?v=tXjoR0IayMA</location> <annotation>Part 3</annotation> <info></info> <meta rel='type'>video</meta> </track> </track> So instead of having them all in different tracks, how can I play all of the parts for "Tutorial 2" back to back with 1 "<location>"? (I know this relates to XML, but I'm guessing this is more relevant to PHP)
-
last bump... Does ANYONE know how to do this? I didn't know it would be this difficult
-
Page 2... Help anyone?
-
Would this even be possible, by the way?
-
Ok, but the problem is that I don't know how to connect that cURL script with the "site.com/1234" URL...if that script really does work.
-
I can't change the coding of "http://site.com/image.php?num=25&loc=china" And..."site.com/1234" links to different "num" values if "site.com/1234" is changed to say..."site.com/4321". That's why I need a way of retrieving the "num" from any URL that I put in. Edit: so the script would be something like this: site.com/script.php?url=site.com/1234 -"Execute 'site.com/1234'" ***..."redirects to site.com/image.php?num25&loc=china" -"echo $_GET['num'] from site.com/image.php?num=25&loc=china"
-
I'm trying to make a script that will do this: 1. Go to the URL "site.com/1234" **That URL redirects me to "site.com/image.php?num=25&loc=china" 2. Retrieves what comes after ".php?num=" and echos it to the user. In this case, it would echo "25" I don't know if it's possible with $_GET because that would mean that the "num=25" was actually sent to the script, not the other way around. I think it's possible with cURL and I have this code that someone else wrote but I don't know how to use it or what it does exactly. $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURN_TRANSFER, FALSE); curl_exec($curl); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $query = parse_url($url, PHP_URL_QUERY); Help please? (note: I made a new topic because my first one seemed to scare people away with all of the replies, lol)