PHP - If File_get_contents Failed...loop?
Ok, I'm having some trouble with file_get_contents failing & am trying to make a loop that will sleep & then retry a maximum of 3 times before giving up & moving to the next item. I tried using a while loop but I'm getting unexpected T_WHILE, which I assume is because it's already in a while loop?
I found this: Code: [Select] $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { but could use some clarification. Will that only trigger if it failes or do I need to include another if statement like Code: [Select] $myfile = file_get_contents("http://example.com"); if ($myfile === FALSE) { $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { sleep(3); $myfile = file_get_contents("http://example.com"); } else { //continue with script I hope that makes sense...trying to explain it as best I can without having to post my actual source code as I've had it stolen off forums before & now I have a clone to compete with. I'm not great at putting this into words so if I need to clarify, please feel free to ask. I appreciate any & all help given. Thanks! Similar TutorialsI am trying to use the google maps to geocode a location but I get this error: Warning: file_get_contents(http://maps.google.com/maps/api/geocode/json?address=New London,+Connecticut,+United States&sensor=false): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request Code: [Select] $location_request = "http://maps.google.com/maps/api/geocode/json?address={$city},+{$real_state},+{$real_country}&sensor=false"; $geocode = file_get_contents($location_request); What am I doing wrong? I tried URL encoding the location request but that also didn't work. Hey guys, every now and then some of my scripts that consistently access headers seem to fail to open the stream. I'm running about 1-50 of these shell scripts at once, but it doesn't seem to make a difference weather I have 1 or 50 scripts open at once. I was wondering if there was a way to tell PHP: Alright, so it failed to open the http stream, I want you to try again until it works. I just want it to try again until it works, because when it doesn't load certain headers, things go very wrong. Thanks. Here's an example of the code where the problem occurs: $Attack = file_get_contents($MobLink."attack?user_id=".$UserID."&target_id=".$TargetID."&auth_key=".$AuthKey); xml_parse_into_struct($iP=xml_parser_create(), $Attack, $iS, $iX);xml_parser_free($iP); echo "$i :.:.: ".strip_tags($iS[$iX['MESSAGE'][0]]['value'])." :.:.:\n\n"; I am using file_get_contents to grab HTML pages. Seems to work fine as a part of a 1-shot function. But as soon as I include the function as part of a loop, it doesn't return anything... for ($i = 0; $i < 10; $i++) { ... getFile($urlArray[$i]; ... } function getFile($whatURL) { return strtolower(file_get_contents( $whatURL )); } I originally had the strtolower(file_get_contents( $whatURL )); line in the for loop but thought there needed to be some sort of pause for the file_get_contents method to function, but neither seems to work. What's the deal? Hey! I am trying to get a database table of users but am running into the error: Warning: file_get_contents(http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=68583) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 in get_user_from_parameter(nabble:utilities.naml:890) - <n.get_user_from_parameter.as_user_page.do/> - public v in C:\xampp\htdocs\website4js\stanford\loadUsernames.php on line 32 I have looked it up and it may be a security thing...The urls I am getting are http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=68583 but the error adds an nodes& part that screws it up. Any way around this? Code: [Select] <?PHP $maxPage = 0; $mainPage = "http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=app_people&node=136"; $mainContent = file_get_contents($mainPage); $pattern = "/(?<=\"Page )\d\d+/"; preg_match_all($pattern, $mainContent, $pageNumb); //find the max page for($i=0;$i<sizeof($pageNumb[0]);$i++) { if($pageNumb[0][$i] > $maxPage) { $maxPage = $pageNumb[0][$i]; } } //echo('Max page is: '.$maxPage.'\n'); //Get an array of all the pages $pages = array(); for($i=1;$i<$maxPage;$i++) { $pages[$i] = "http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=app_people&node=136&i=".($i*20); } //print_r($userPages); //Get personal page urls and add to MySQL mysql_connect("localhost" , "root") or die("Cant connect"); mysql_select_db("protegeusers") or die("Cant find database"); foreach($pages as $url) { $urlContents = file_get_contents($url); $pattern = "/http:\/\/protege-ontology-editor-knowledge-acquisition-system\.136\.n4\.nabble\.com\/template\/NamlServlet\.jtp\?macro=.+;user=\d+/"; preg_match_all($pattern, $urlContents, $personalPage); foreach($personalPage as $user) { for($i=0; $i<sizeof($user);$i++) { [color=green]$userContents = file_get_contents($user[$i]);[/color] $pattern1 = "/user\/SendEmail\.jtp\?type=user.+;user=\d+/"; $pattern2 = "/(?<=\">Send Email to ).+(?=<)/"; preg_match_all($pattern1, $userContents, $userEmail); preg_match_all($pattern2, $userContents, $username); [color=green]print_r($username); print_r($email);[/color] //$query = "INSERT INTO users (username, userurl) values ('$userName','$userUrl')"; //mysql_query($query); } } } ?> I am trying to figure how to code around this. I have a DOM scraper function that pulls urls from my database, opens the page, scrapes the data, and then moves onto the next URL to scrape. my issue is that if the page fails to load the script bombs and I have to restart it again. Trying to figure out how if the Code: [Select] $html->find('div[class="itemHeader address"]') as $div fails to open the page it just skips the DOM inspection. Here is my error... Failed to open stream: HTTP Request failed. Here is where I am at with my script.... Code: [Select] mysql_select_db("scraped") or die(mysql_error()); $result = mysql_query("SELECT PKEY, URL, HASSCRAPED, SHOULDSCRAPE FROM CRAWLED WHERE SHOULDSCRAPE ='1' AND HASSCRAPED = '0'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { mysql_query("UPDATE CRAWLED SET CRAWLED.HASSCRAPED = '1' WHERE CRAWLED.URL = '" . $row['URL'] . "'"); $html = file_get_html($row['URL']); foreach($html->find('div[class="itemHeader address"]') as $div) { foreach($div->find('a') as $element){ $CleanData = CleanData($element->innertext); if (strlen($CleanData[0]) > 5){ mysql_query("INSERT INTO SCRAPED (ADDR1, CITY, STATE, ZIP, URL, DATE) VALUES ('" . $CleanData[0] . "','" . $CleanData[1] . "','" . $CleanData[2] . "','" . $CleanData[3] . "','". $row['URL'] . "','". date( 'Y-m-d H:i:s ' ) ."')"); } } } $html->clear(); unset($html); unset($CleanData); } function CleanData($data) { $NewData = trim($data); $NewData = str_replace("<em>", "", $NewData); $AddrCityStateZip = explode("</em>",$NewData); $CityStateZip = explode(",",$AddrCityStateZip[1]); $StateZip = explode(' ',$CityStateZip[1]); $NewDataArray = array ($AddrCityStateZip[0], $CityStateZip[0], $StateZip[1], $StateZip[2]); return $NewDataArray; unset($NewData); unset($AddrCityStateZip); unset($CityStateZip); unset($StateZip); } mysql_close($link); echo 'Scraping has compleated without error'; Can someone tell me why the first example works, but the second example does not? Code: [Select] file_get_contents('http://pinalcountyaz.gov/Departments/Treasurer/Pages/TaxBillSearch.aspx?p=10006015E-*'); Code: [Select] $url = 'http://pinalcountyaz.gov/Departments/Treasurer/Pages/TaxBillSearch.aspx?p=10006015E-*'; file_get_contents($url); <?php $1 = file_get_contents(""); $2 = json_decode($1); $3 = $2->result; var_dump($myData1); foreach($3 as $key => $item): echo $item->Users->UserObject->UserName; endforeach; ?> { "result": [ { "ID": 1, "Users": [ { "UserObject": { "UserName": "test1" }, "...": 2 }, { "UserObject": { "UserName": "test2" }, "...": 2 } ], "IsActive": true } ], "error": false }
I get this error Notice: Trying to get property 'UserObject' of non-object in C:\xampp\htdocs\dashboard-master\chart.php on line 10 Hello I wanted to query something from an API, but now I have 2 times money see example below. How can I only output one of them I have already looked for a solution but cannot find any or I am looking wrong { "result": [ { "Money": 45674569.88764 }, { "Money": 546.6544356456 } ], "test": 0 } <?php $myData = file_get_contents(""); $myObject = json_decode($myData); $myObjectMap = $myObject->result; ?> <?php foreach($myObjectMap as $key => $item): ?> <?PHP echo $item->Money; ?>
This works great but I only need part of the page for example the right column...can I do this with a class or some how. What this is is pulling information from another site. Code: [Select] <?php $g = file_get_contents("http://www.site.com/index.php"); echo ($g); ?> I coded this, it has over 600 lines... Im not sure if I should post all of it so I will. When using a account that does not exist it gives an "failed to open stream Error". Code: [Select] <?php $user = "S U O M I"; $user1 = "Tezz"; if(isset($_GET['user'])) { if(!empty($_GET['user'])) { $user = $_GET['user']; } } if(isset($_GET['user1'])) { if(!empty($_GET['user1'])) { $user1 = $_GET['user1']; } } //Skill Grabs $order = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "Dungeoneering"); $get = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user"); $get = explode("\n", $get); $i = 0; foreach ($order as $key => $value) { $value = strtolower($value); $temp = explode(",", $get[$i]); $temp = array("rank" => $temp[0], "level" => $temp[1], "exp" => $temp[2]); $stats[$value] = $temp; $eval = "\$$value = array(\$temp[\"rank\"], \$temp[\"level\"], \$temp[\"exp\"]);"; eval($eval); $i++; } //End Skill Grabs $order1 = array("Overall1", "Attack1", "Defence1", "Strength1", "Hitpoints1", "Ranged1", "Prayer1", "Magic1", "Cooking1", "Woodcutting1", "Fletching1", "Fishing1", "Firemaking1", "Crafting1", "Smithing1", "Mining1", "Herblore1", "Agility1", "Thieving1", "Slayer1", "Farming1", "Runecraft1", "Hunter1", "Construction1", "Summoning1", "Dungeoneering1"); $get1 = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user1"); $get1 = explode("\n", $get1); $i1 = 0; foreach ($order1 as $key1 => $value1) { $value1 = strtolower($value1); $temp1 = explode(",", $get1[$i1]); $temp1 = array("rank1" => $temp1[0], "level1" => $temp1[1], "exp1" => $temp1[2]); $stats1[$value1] = $temp1; $eval1 = "\$$value1 = array(\$temp1[\"rank1\"], \$temp1[\"level1\"], \$temp1[\"exp1\"]);"; eval($eval1); $i1++; } //End Skill Grabs echo "<table border='1' cellpadding='5'>"; echo "<tr>"; echo "<td colspan='4'><b><center>".strtoupper($user)."</center></b></td>"; echo "<td></td>"; echo "<td colspan='4'><b><center>".strtoupper($user1)."</center></b></td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Skills</b></td>"; echo "<td><b>Rank</b></td>"; echo "<td><b>Level</b></td>"; echo "<td><b>XP</b></td>"; echo "<td></td>"; echo "<td><b>Skills</b></td>"; echo "<td><b>Rank</b></td>"; echo "<td><b>Level</b></td>"; echo "<td><b>XP</b></td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Overall</b></td>"; echo "<td>";if($overall[0]<=-1){echo "Not Ranked";}else{echo $overall[0];} echo "</td>"; echo "<td>".$overall[1]."</td>"; echo "<td>".$overall[2]."</td>"; echo "<td>"; if ($overall[2] == $overall1[2]){ echo "<img src='images/equal.png' />"; } elseif ($overall[2] <= $overall1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($overall[2] >= $overall1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Overall</b></td>"; echo "<td>";if($overall1[0]<=-1){echo "Not Ranked";}else{echo $overall1[0];} echo "</td>"; echo "<td>".$overall1[1]."</td>"; echo "<td>".$overall1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Attack</b></td>"; echo "<td>";if($attack[0]<=-1){echo "Not Ranked";}else{echo $attack[0];} echo "</td>"; echo "<td>".$attack[1]."</td>"; echo "<td>".$attack[2]."</td>"; echo "<td>"; if ($attack[2] == $attack1[2]){ echo "<img src='images/equal.png' />"; } elseif ($attack[2] <= $attack1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($attack[2] >= $attack1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Attack</b></td>"; echo "<td>";if($attack1[0]<=-1){echo "Not Ranked";}else{echo $attack1[0];} echo "</td>"; echo "<td>".$attack1[1]."</td>"; echo "<td>".$attack1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Defence</b></td>"; echo "<td>";if($defence[0]<=-1){echo "Not Ranked";}else{echo $defence[0];} echo "</td>"; echo "<td>".$defence[1]."</td>"; echo "<td>".$defence[2]."</td>"; echo "<td>"; if ($defence[2] == $defence1[2]){ echo "<img src='images/equal.png' />"; } elseif ($defence[2] <= $defence1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($defence[2] >= $defence1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Defence</b></td>"; echo "<td>";if($defence1[0]<=-1){echo "Not Ranked";}else{echo $defence1[0];} echo "</td>"; echo "<td>".$defence1[1]."</td>"; echo "<td>".$defence1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Strength</b></td>"; echo "<td>";if($strength[0]<=-1){echo "Not Ranked";}else{echo $strength[0];} echo "</td>"; echo "<td>".$strength[1]."</td>"; echo "<td>".$strength[2]."</td>"; echo "<td>"; if ($strength[2] == $strength1[2]){ echo "<img src='images/equal.png' />"; } elseif ($strength[2] <= $strength1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($strength[2] >= $strength1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Strength</b></td>"; echo "<td>";if($strength1[0]<=-1){echo "Not Ranked";}else{echo $strength1[0];} echo "</td>"; echo "<td>".$strength1[1]."</td>"; echo "<td>".$strength1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Constitution</b></td>"; echo "<td>";if($hitpoints[0]<=-1){echo "Not Ranked";}else{echo $hitpoints[0];} echo "</td>"; echo "<td>".$hitpoints[1]."</td>"; echo "<td>".$hitpoints[2]."</td>"; echo "<td>"; if ($hitpoints[2] == $hitpoints1[2]){ echo "<img src='images/equal.png' />"; } elseif ($hitpoints[2] <= $hitpoints1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($hitpoints[2] >= $hitpoints1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Constitution</b></td>"; echo "<td>";if($hitpoints1[0]<=-1){echo "Not Ranked";}else{echo $hitpoints1[0];} echo "</td>"; echo "<td>".$hitpoints1[1]."</td>"; echo "<td>".$hitpoints1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Ranged</b></td>"; echo "<td>";if($ranged[0]<=-1){echo "Not Ranked";}else{echo $ranged[0];} echo "</td>"; echo "<td>".$ranged[1]."</td>"; echo "<td>".$ranged[2]."</td>"; echo "<td>"; if ($ranged[2] == $ranged1[2]){ echo "<img src='images/equal.png' />"; } elseif ($ranged[2] <= $ranged1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($ranged[2] >= $ranged1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Ranged</b></td>"; echo "<td>";if($ranged1[0]<=-1){echo "Not Ranked";}else{echo $ranged1[0];} echo "</td>"; echo "<td>".$ranged1[1]."</td>"; echo "<td>".$ranged1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Prayer</b></td>"; echo "<td>";if($prayer[0]<=-1){echo "Not Ranked";}else{echo $prayer[0];} echo "</td>"; echo "<td>".$prayer[1]."</td>"; echo "<td>".$prayer[2]."</td>"; echo "<td>"; if ($prayer[2] == $prayer1[2]){ echo "<img src='images/equal.png' />"; } elseif ($prayer[2] <= $prayer1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($prayer[2] >= $prayer1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Prayer</b></td>"; echo "<td>";if($prayer1[0]<=-1){echo "Not Ranked";}else{echo $prayer1[0];} echo "</td>"; echo "<td>".$prayer1[1]."</td>"; echo "<td>".$prayer1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Magic</b></td>"; echo "<td>";if($magic[0]<=-1){echo "Not Ranked";}else{echo $magic[0];} echo "</td>"; echo "<td>".$magic[1]."</td>"; echo "<td>".$magic[2]."</td>"; echo "<td>"; if ($magic[2] == $magic1[2]){ echo "<img src='images/equal.png' />"; } elseif ($magic[2] <= $magic1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($magic[2] >= $magic1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Magic</b></td>"; echo "<td>";if($magic1[0]<=-1){echo "Not Ranked";}else{echo $magic1[0];} echo "</td>"; echo "<td>".$magic1[1]."</td>"; echo "<td>".$magic1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Cooking</b></td>"; echo "<td>";if($cooking[0]<=-1){echo "Not Ranked";}else{echo $cooking[0];} echo "</td>"; echo "<td>".$cooking[1]."</td>"; echo "<td>".$cooking[2]."</td>"; echo "<td>"; if ($cooking[2] == $cooking1[2]){ echo "<img src='images/equal.png' />"; } elseif ($cooking[2] <= $cooking1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($cooking[2] >= $cooking1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Cooking</b></td>"; echo "<td>";if($cooking1[0]<=-1){echo "Not Ranked";}else{echo $cooking1[0];} echo "</td>"; echo "<td>".$cooking1[1]."</td>"; echo "<td>".$cooking1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Woodcutting</b></td>"; echo "<td>";if($woodcutting[0]<=-1){echo "Not Ranked";}else{echo $woodcutting[0];} echo "</td>"; echo "<td>".$woodcutting[1]."</td>"; echo "<td>".$woodcutting[2]."</td>"; echo "<td>"; if ($woodcutting[2] == $woodcutting1[2]){ echo "<img src='images/equal.png' />"; } elseif ($woodcutting[2] <= $woodcutting1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($woodcutting[2] >= $woodcutting1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Woodcutting</b></td>"; echo "<td>";if($woodcutting1[0]<=-1){echo "Not Ranked";}else{echo $woodcutting1[0];} echo "</td>"; echo "<td>".$woodcutting1[1]."</td>"; echo "<td>".$woodcutting1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Fletching</b></td>"; echo "<td>".$fletching[0]."</td>"; echo "<td>".$fletching[1]."</td>"; echo "<td>".$fletching[2]."</td>"; echo "<td>"; if ($fletching[2] == $fletching1[2]){ echo "<img src='images/equal.png' />"; } elseif ($fletching[2] <= $fletching1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($fletching[2] >= $fletching1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Fletching</b></td>"; echo "<td>";if($fletching1[0]<=-1){echo "Not Ranked";}else{echo $fletching1[0];} echo "</td>"; echo "<td>".$fletching1[1]."</td>"; echo "<td>".$fletching1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Fishing</b></td>"; echo "<td>";if($fishing[0]<=-1){echo "Not Ranked";}else{echo $fishing[0];} echo "</td>"; echo "<td>".$fishing[1]."</td>"; echo "<td>".$fishing[2]."</td>"; echo "<td>"; if ($fishing[2] == $fishing1[2]){ echo "<img src='images/equal.png' />"; } elseif ($fishing[2] <= $fishing1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($fishing[2] >= $fishing1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Fishing</b></td>"; echo "<td>";if($fishing1[0]<=-1){echo "Not Ranked";}else{echo $fishing1[0];} echo "</td>"; echo "<td>".$fishing1[1]."</td>"; echo "<td>".$fishing1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Firemaking</b></td>"; echo "<td>";if($firemaking[0]<=-1){echo "Not Ranked";}else{echo $firemaking[0];} echo "</td>"; echo "<td>".$firemaking[1]."</td>"; echo "<td>".$firemaking[2]."</td>"; echo "<td>"; if ($firemaking[2] == $firemaking1[2]){ echo "<img src='images/equal.png' />"; } elseif ($firemaking[2] <= $firemaking1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($firemaking[2] >= $firemaking1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Firemaking</b></td>"; echo "<td>";if($firemaking1[0]<=-1){echo "Not Ranked";}else{echo $firemaking1[0];} echo "</td>"; echo "<td>".$firemaking1[1]."</td>"; echo "<td>".$firemaking1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Crafting</b></td>"; echo "<td>";if($crafting[0]<=-1){echo "Not Ranked";}else{echo $crafting[0];} echo "</td>"; echo "<td>".$crafting[1]."</td>"; echo "<td>".$crafting[2]."</td>"; echo "<td>"; if ($crafting[2] == $crafting1[2]){ echo "<img src='images/equal.png' />"; } elseif ($crafting[2] <= $crafting1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($crafting[2] >= $crafting1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Crafting</b></td>"; echo "<td>";if($crafting1[0]<=-1){echo "Not Ranked";}else{echo $crafting1[0];} echo "</td>";; echo "<td>".$crafting1[1]."</td>"; echo "<td>".$crafting1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Smithing</b></td>"; echo "<td>";if($smithing[0]<=-1){echo "Not Ranked";}else{echo $smithing[0];} echo "</td>"; echo "<td>".$smithing[1]."</td>"; echo "<td>".$smithing[2]."</td>"; echo "<td>"; if ($smithing[2] == $smithing1[2]){ echo "<img src='images/equal.png' />"; } elseif ($smithing[2] <= $smithing1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($smithing[2] >= $smithing1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Smithing</b></td>"; echo "<td>";if($smithing1[0]<=-1){echo "Not Ranked";}else{echo $smithing1[0];} echo "</td>"; echo "<td>".$smithing1[1]."</td>"; echo "<td>".$smithing1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Mining</b></td>"; echo "<td>";if($mining[0]<=-1){echo "Not Ranked";}else{echo $mining[0];} echo "</td>"; echo "<td>".$mining[1]."</td>"; echo "<td>".$mining[2]."</td>"; echo "<td>"; if ($mining[2] == $mining1[2]){ echo "<img src='images/equal.png' />"; } elseif ($mining[2] <= $mining1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($mining[2] >= $mining1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Mining</b></td>"; echo "<td>";if($mining1[0]<=-1){echo "Not Ranked";}else{echo $mining1[0];} echo "</td>"; echo "<td>".$mining1[1]."</td>"; echo "<td>".$mining1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Herblore</b></td>"; echo "<td>";if($herblore[0]<=-1){echo "Not Ranked";}else{echo $herblore[0];} echo "</td>"; echo "<td>".$herblore[1]."</td>"; echo "<td>".$herblore[2]."</td>"; echo "<td>"; if ($herblore[2] == $herblore1[2]){ echo "<img src='images/equal.png' />"; } elseif ($herblore[2] <= $herblore1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($herblore[2] >= $herblore1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Herblore</b></td>"; echo "<td>";if($herblore1[0]<=-1){echo "Not Ranked";}else{echo $herblore1[0];} echo "</td>"; echo "<td>".$herblore1[1]."</td>"; echo "<td>".$herblore1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Agility</b></td>"; echo "<td>";if($agility[0]<=-1){echo "Not Ranked";}else{echo $agility[0];} echo "</td>"; echo "<td>".$agility[1]."</td>"; echo "<td>".$agility[2]."</td>"; echo "<td>"; if ($agility[2] == $agility1[2]){ echo "<img src='images/equal.png' />"; } elseif ($agility[2] <= $agility1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($agility[2] >= $agility1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Agility</b></td>"; echo "<td>";if($agility1[0]<=-1){echo "Not Ranked";}else{echo $agility1[0];} echo "</td>"; echo "<td>".$agility1[1]."</td>"; echo "<td>".$agility1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Thieving</b></td>"; echo "<td>";if($thieving[0]<=-1){echo "Not Ranked";}else{echo $thieving[0];} echo "</td>"; echo "<td>".$thieving[1]."</td>"; echo "<td>".$thieving[2]."</td>"; echo "<td>"; if ($thieving[2] == $thieving1[2]){ echo "<img src='images/equal.png' />"; } elseif ($thieving[2] <= $thieving1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($thieving[2] >= $thieving1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Thieving</b></td>"; echo "<td>";if($thieving1[0]<=-1){echo "Not Ranked";}else{echo $thieving[0];} echo "</td>"; echo "<td>".$thieving1[1]."</td>"; echo "<td>".$thieving1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Slayer</b></td>"; echo "<td>";if($slayer[0]<=-1){echo "Not Ranked";}else{echo $slayer[0];} echo "</td>"; echo "<td>".$slayer[1]."</td>"; echo "<td>".$slayer[2]."</td>"; echo "<td>"; if ($slayer[2] == $slayer1[2]){ echo "<img src='images/equal.png' />"; } elseif ($slayer[2] <= $slayer1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($slayer[2] >= $slayer1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Slayer</b></td>"; echo "<td>";if($slayer1[0]<=-1){echo "Not Ranked";}else{echo $slayer1[0];} echo "</td>"; echo "<td>".$slayer1[1]."</td>"; echo "<td>".$slayer1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Farming</b></td>"; echo "<td>";if($farming[0]<=-1){echo "Not Ranked";}else{echo $farming[0];} echo "</td>"; echo "<td>".$farming[1]."</td>"; echo "<td>".$farming[2]."</td>"; echo "<td>"; if ($farming[2] == $farming1[2]){ echo "<img src='images/equal.png' />"; } elseif ($farming[2] <= $farming1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($farming[2] >= $farming1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Farming</b></td>"; echo "<td>";if($farming1[0]<=-1){echo "Not Ranked";}else{echo $farming[0];} echo "</td>"; echo "<td>".$farming1[1]."</td>"; echo "<td>".$farming1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Runecrafting</b></td>"; echo "<td>";if($runecraft[0]<=-1){echo "Not Ranked";}else{echo $runecraft[0];} echo "</td>"; echo "<td>".$runecraft[1]."</td>"; echo "<td>".$runecraft[2]."</td>"; echo "<td>"; if ($runecraft[2] == $runecraft1[2]){ echo "<img src='images/equal.png' />"; } elseif ($runecraft[2] <= $runecraft1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($runecraft[2] >= $runecraft1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Runecrafting</b></td>"; echo "<td>";if($runecraft1[0]<=-1){echo "Not Ranked";}else{echo $runecraft1[0];} echo "</td>"; echo "<td>".$runecraft1[1]."</td>"; echo "<td>".$runecraft1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Hunter</b></td>"; echo "<td>";if($hunter[0]<=-1){echo "Not Ranked";}else{echo $hunter[0];} echo "</td>"; echo "<td>".$hunter[1]."</td>"; echo "<td>".$hunter[2]."</td>"; echo "<td>"; if ($hunter[2] == $hunter1[2]){ echo "<img src='images/equal.png' />"; } elseif ($hunter[2] <= $hunter1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($hunter[2] >= $hunter1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Hunter</b></td>"; echo "<td>";if($hunter1[0]<=-1){echo "Not Ranked";}else{echo $hunter1[0];} echo "</td>"; echo "<td>".$hunter1[1]."</td>"; echo "<td>".$hunter1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Construction</b></td>"; echo "<td>";if($construction[0]<=-1){echo "Not Ranked";}else{echo $construction[0];} echo "</td>"; echo "<td>".$construction[1]."</td>"; echo "<td>".$construction[2]."</td>"; echo "<td>"; if ($construction[2] == $construction1[2]){ echo "<img src='images/equal.png' />"; } elseif ($construction[2] <= $construction1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($construction[2] .= $construction1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Construction</b></td>"; echo "<td>";if($construction1[0]<=-1){echo "Not Ranked";}else{echo $construction1[0];} echo "</td>"; echo "<td>".$construction1[1]."</td>"; echo "<td>".$construction1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Summoning</b></td>"; echo "<td>";if($summoning[0]<=-1){echo "Not Ranked";}else{echo $summoning[0];} echo "</td>"; echo "<td>".$summoning[1]."</td>"; echo "<td>".$summoning[2]."</td>"; echo "<td>"; if ($summoning[2] == $summoning1[2]){ echo "<img src='images/equal.png' />"; } elseif ($summoning[2] <= $summoning1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($summoning[2] >= $summoning1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Summoning</b></td>"; echo "<td>";if($summoning1[0]<=-1){echo "Not Ranked";}else{echo $summoning[0];} echo "</td>"; echo "<td>".$summoning1[1]."</td>"; echo "<td>".$summoning1[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Dungeoneering</b></td>"; echo "<td>";if($dungeoneering[0]<=-1){echo "Not Ranked";}else{echo $dungeoneering[0];} echo "</td>"; echo "<td>".$dungeoneering[1]."</td>"; echo "<td>".$dungeoneering[2]."</td>"; echo "<td>"; if ($dungeoneering[2] == $dungeoneering1[2]){ echo "<img src='images/equal.png' />"; } elseif ($dungeoneering[2] <= $dungeoneering1[2]){ echo "<img src='images/downArrow.png' />"; } elseif ($dungeoneering[2] >= $dungeoneering1[2]){ echo "<img src='images/upArrow.png' />"; } echo "</td>"; echo "<td><b>Dungeoneering</b></td>"; echo "<td>";if($dungeoneering1[0]<=-1){echo "Not Ranked";}else{echo $dungeoneering1[0];} echo "</td>"; echo "<td>".$dungeoneering1[1]."</td>"; echo "<td>".$dungeoneering1[2]."</td>"; echo "</tr>"; echo "</table>"; ?> How would I go about fixing this error? im trying to display the contents of a file within a div. plain html is fine but i need this file to have php variables within it. eg: the file tos.php <?php $foo = 'bar'; ?> <p></php echo $foo; ?></p> the code to display it: file_get_contents(tos.php); but this func only displays the html and doesnt print the contents of anything between php tags. any ideas? Hi heres what I would like to do, im sure its not the best way to do it but its the only way I have used in the past . getting content string <?php $file = file_get_contents('contents.txt', 'r'); echo $file; ?> usualy I would use a edit link with this code <?php if(session_is_registered(myusername)){ ?><a href="javascript:open1()"><div id="edit_link">Edit</a></div><?php } ?> But what I would like to do now is to skip the edit link and just make the content string a link once the user is logged in they will be able to click on the content string and it will activate the javascript:open1() Many thanks for your help Okay, so I'm trying to make a service to detect proxies. Heres what I need to know.. This is how I have it set up: 1. I have a file on mysite.com/check.php 2. My clients create a page to load my check.php file on THEIR website using file_get_contents(); Like: file_get_contents("http://mysite.com/check.php?ip=$_SERVER['REMOTE_ADDR']"); 3. My system checks for a proxy using HTTP vars, how would I get them?? Like.. if I echo $_SERVER['REMOTE_ADDR']; out on the page on MY end, it will echo the servers IP to check is using step #2 with file_get_contents(); Can anyone please help me? I am willing to pay a little, if needed :/ Thanks in advance! What I am trying to do is pull the content of another page which works fine and then do echo statements. It does display the content of the page but not the echo statements. outside page Code: [Select] lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum <?php echo $stateinsert ?> lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum <?php echo $cityinsert ?> <?php echo $stateinsert ?> lorem ipsum lorem ipsum lorem ipsum lorem ipsum <?php echo $countyinsert ?> Lorum Ipsom Lorum Ipsom Lorum Ipsom </p> Code: [Select] <?php $cityinsert = "Auburn"; $stateinsert = "Alabama"; $countyinsert = "Jefferson"; $table = "auburnAL"; ?> <?php $d = file_get_contents("http://mysite.com/includes/leftcopy.php"); echo ($d); ?> It displays the lorem ipsum but won't display the echo statements. $body = <<<EMAIL Hello <[fname]>, You've registered and need to activate your account. Click the link below or paste it into the URL bar of your web browser http://blahblah.com/activate.php?id=<[id]>&code=< Code: [Select] > Thanks! Team EMAIL; The <[id]> isn't working. It literally sends out <[id]> in the email. I want to load and display the content of a text file (actually it is a cache file). I tested both method using a long for loop as Code: [Select] for ($i=0; $i < 10000; $i++) { $handle = fopen("test.txt", "r"); $text = fread($handle, filesize("test.txt")); fclose($handle); echo $text; }and Code: [Select] for ($i=0; $i < 10000; $i++) { $text = file_get_contents("test.txt"); echo $text; } but the results were similar, though with a large distribution of the comparative data. The speed of a method was 0.5 to 2.0 faster than the other one (in various runs). Which method do you recommend? Could you please quote the pros and cons of each method? $HEADER = "http://www.google.com"; for($cwb=1; $cwb!=100; $cwb++) { $repeat = file_get_contents($HEADER); $msg = explode('<message>', $repeat); $msg = explode('</', $msg[1]); echo "#$cwb: ".$msg[0]."\n"; } why is this much faster? $HEADER = "http://www.google.com"; $REPEAT = 100; // times to repeat $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); for($cwb=1; $cwb!=$REPEAT; $cwb++) { curl_setopt($ch, CURLOPT_URL, $HEADER); $msg = explode('<message>', curl_exec($ch)); $msg = explode('</', $msg[1]); echo "#$cwb: ".$msg[0]."\n"; } while($ch); curl_close($ch); is there anything faster than both of these options? Hello everyone. First post and am very much a learner.. I have been modifying a Shipping Module, for my Zen-cart website, on a Local Development setup on my PC. I have it working perfectly on my local setup but once I upload it to my website it won't work! (Pride deflating..) The PHP versions, on both setups are the same. I'm really stuck with this one and would really appreciate anyones help. The problem may be with urlencode, but I'm not sure where.I only have to insert the 'postcode' and 'city' variables into the URL parameters, the rest are just hardcoded. I had to urlencode the 'city' variable before insertion, due to the spaces between many town names. They insist on a space being made after the city ($foo) argument also, which is why i included '%20'. // First get the destination postcode and city name $topcode = $order->delivery['postcode']; $zoo = $order->delivery['city']; $foo = urlencode($zoo); if ( $topcode == '' ){ // Something is wrong, we didn't find any dest zip $this->quotes['error'] = MODULE_SHIPPING_XXX_NO_POSTCODE_FOUND; return $this->quotes; } //SENDS A REQUEST TO THE API FOR THE XML FILE $url = "http://www.xxxxxxx.org/Magic94Scripts/mgrqispi94.dll?appname=FW&PRGNAME=FastLocatorRecord&ARGUMENTS=-A1,-ANTH,-A$foo%20,-A$topcode,-A10,-N1"; $xml = file_get_contents($url) ; //TRANSFORMS THE RETURNED XML INTO AN OBJECT $rec = simplexml_load_string($xml); Hey guys i am trying to extract the HTML of a loop of links. Each links are diffrent pages and i manualy cheked and there all diffrent ... but for some reason, the loop always sends back the same html ... the one from the first loop. while($i<=3){ echo file_get_contents("http://www.amazon.com/s/ref=nb_sb_noss_1/187-7591397-0314036?url=search-alias%3Dvideogames&field-keywords=ps3#/ref=sr_pg_$i?rh=n%3A468642%2Ck%3Aps3+game&page=$i&d=1&keywords=ps3+game&ie=UTF8&qid=1333219791"); echo "<hr>"; $i++; } Normaly i should get page 1 2 3 ... but i get 3 times the page 1 ... the URL is good because if i manualy open them the content is diffrent in each page Hi guys, I have a very simple php script that's supposed to work but doesn't. The script looks like this... <?php $response = file_get_contents("http://localhost:8090/MyWebApp/MyServlet", false, NULL) echo $response ?> which seems to return nothing. This is supposed to call a java servlet on the local machine. However, the servlet does not get called (I put a breakpoint in the servlet so I'd know if it were called). When I navigate to this php from a web browser, I get back an empty page (as if there's an error or something). However, if I change the above line to use http://www.google.com as the URL, it works (I can hit the php page from my browser and get back a google-looking page, minus some pictures and what not). For some reason, the call to a localhost URL does not seem to work, even though the servlet is, in fact, running. I have tested this by calling "curl http://localhost:8090/MyWebApp/MyServlet" from my linux terminal and correctly getting the servlet response. Does anyone know why this does not work in PHP? Thanks, --Ronen |