PHP - Reading And Displaying Data From Xml File
Hello again. I'm trying to load data from a Facebook Share Data XML file and then displaying them in a WordPress plugin. Here's my code so far:
// Fetch Share Count Data function fb_button () { $fbshareUrl = urlencode(get_permalink($post->ID)); $fbshareTitle = urlencode($post->post_title); $fbLinkStats = simplexml_load_file('http://api.facebook.com/restserver.php?method=links.getStats&urls='.$shareUrl); $fb_params = '?u=' . $fbshareUrl . '&t=' . $fbshareTitle . '' ; // Vertical Facebook Button $fb_share = ' <div class="fsbsharer" id="fb"> <a href="http://www.facebook.com/sharer.php' . $fb_params . '" class="facebookShare"> <span class="fb_share_size_Small fb_share_count_wrapper"> <span></span> <span class="fb_share_count_nub_top "></span> <span class="fb_share_count fb_share_count_top"> <div class="fb_share_count_inner"> '. $fbLinkStats->link_stat->total_count .' </div> </div> <span style="cursor:pointer;" class="FBConnectButton FBConnectButton_Small"><span class="FBConnectButton_Text">Share</span></span> </a> </div> '; echo $fb_share; } This code works for everything except the title and the share count. I can fix the title myself but the share count isn't working. When I use this in plain HTML: <?php echo $fbLinkStats->link_stat->total_count.''; ?> it works fine, but when I combine it all into another function to echo, it no longer works properly. Thanks. Similar TutorialsSo, I'm trying to get this read my text document "news.txt" and display the contents. My code: Code: [Select] div.newscontent{ padding:0px; margin-top:60px; margin-bottom:0px; margin-left:400px; margin-right:0px; position:absolute; width:457px; height:330px; text-align:center; color:#FFFFFF; } Code: [Select] <div class='newscontent'> <?PHP $filename = "news.txt"; $arr = file($filename); foreach($arr as $line){ print $line . "<br/>"; } ?> </div> This is the output I get: Code: [Select] "; } ?> Whats wrong? Well, im a n00b for php, and what i need is a php script which will read data from .xml file and write it into .txt file. Can someone help me? Example of .xml file : <?xml version="1.0" encoding="utf-8"?> <tv generator-info-name="NeTXMLTV/1.0.0.0" source-info-url="http://www.net-tv.hr/" source-info-name="NeT TV XMLTV" source-data-url="http://www.net-tv.hr/xmltv/net-pregled-programa-xmltv.xml"> <programme channel="NeT TV" start="20110413063000 +0200" stop="20110413080000 +0200"> <title lang="hr">JUTARNJI EXPRESS</title> <category lang="hr">glazbeno-informativni program</category> <desc lang="hr">Glazbeno informativna emisija sa servisnim informacijama i jutarnjim temperaturama, idealna za jutarnje buđenje uz toplu kavu ili čaj....</desc> </programme> </tv> I need the .txt file to look like this: 201104130630 - 201104130800 JUTARNJI EXPRESS glazbeno-informativni program Glazbeno informativna emisija sa servisnim informacijama i jutarnjim temperaturama, idealna za jutarnje buđenje uz toplu kavu ili čaj.... Can someone please help me? thanks hello everyone, please anyone can help me how to read data of excel file in php Hello All, Please excuse my lack of knowledge in advance, I'm a beginner but pick things up relatively quickly, and tend to do things by trial and error. I would appreciate any help that anyone could offer with the following: I would like to retrieve two pieces of data from a "text file" and use them to calculate a result from a function I have in javascript. An example of the javascript code is: <script type="text/javascript"> function calculate() { var drybulb = document.calc_form.drybulb.value; var relhum = document.calc_form.relhum.value; var answer = ''; if (drybulb !== '' && relhum !== '') { answer = (0.567*drybulb*1) + (0.393 * (relhum*1/100 * 6.105 * Math.exp(17.27 * drybulb / (237.7 + drybulb*1)))) + 3.94; } document.calc_form.answer.value = answer; return false; } </script> Currently this is evaluated with entry from a simple html form, but I would like to have this performed "automatically". The "text file" that I would like to access is here, not on my server: http://www.bom.gov.au/fwo/IDV60901/IDV60901.94870.axf I would like to extract the "air_temp" and "rel_hum" values under the [data] section for use in my function. I just need the "most recent" values (i.e. first), not all those contained in the file. This is a single record from that section (sorry for the mess this no doubt makes): [data] sort_order,wmo,name[80],history_product[80],local_date_time[80],local_date_time_full[80],aifstime_utc[80],air_temp,apparent_t,cloud[80],cloud_base_m,cloud_oktas,cloud_type[80],cloud_type_id,delta_t,dewpt,gust_kmh,gust_kt,lat,lon,press,press_msl,press_qnh,press_tend[80],rain_trace[80],rel_hum,sea_state[80],swell_dir_worded[80],swell_height,swell_period,vis_km[80],weather[80],wind_dir[80],wind_spd_kmh,wind_spd_kt 0,94870,"Moorabbin Airport","IDV60901","27/10:00pm","20120227220000","20120227110000",18.8,19.3,"Partly cloudy",510,3,"-",-9999,0.8,17.5,13,7,-38.0,145.1,1013.5,-9999.0,1013.5,"-","11.4",92,"-","-",-9999.0,-9999,"10","-","S",11,6 Would it be possible to obtain these values using PHP?, and if so any advice on how this could be done (noting my minimal knowledge) would be greatly appreciated. Cheers. Let's say I have a script that updates the database every 5 minutes. Or fwrites to a text file at an interval. How do I say create a dynamic textbook or label that displays this information and automatically UPDATES on the page without the user clicking on REFRESH? Hi, guys. I'm trying to wrap my head around trying to read a header in a binary file in php. So, far, I have been able to get the data into a string using file_get_contents. Now, I think I need to use unpack, but it's a bit confusing to me still. For example, my file starts by having a 1 byte version number, 4 bytes to represent a number of walls, then "number of walls" * 40 bytes for the actual walls. But, the problem is, the wall itself is a structure composed of various elements to make up that 40 bytes, from which I'll need to pick out a specific area of interest. I can do this easily in C, but in php. I can't think how to grab the info. Any ideas? Maybe just how to read 1 byte, 4 bytes, then "number of walls" * 40 bytes will get me in the right direction. I'm trying to use PHP to read data from EDGAR, the SEC's website for company filings. Filings are in XBRL, a standard for XML. I'm having trouble pulling data using PHP. Here is a link to the data: http://www.sec.gov/Archives/edgar/da...g-20101231.xml Using PHP, I'm trying to get the data from, for example, the following tag: <us-gaap:Assets contextRef="eol_PE633170--1010-K0013_STD_0_20091231_0" unitRef="iso4217_USD" decimals="-6">40497000000</us-gaap:Assets> I've been unsuccessful thus far in getting this data - do you have any suggestions on how to do that? Thank you! OK, so I am trying to read exif data from images and have come up against a snag that I cannot see the answer to. I know that what I have at present is pretty basic, but I want to be sure that I know how to access the bits I want before tidying it up into something more sophisticated. The coide I have is this:- Code: [Select] $exif = exif_read_data('brass jaw.jpg', 'EXIF'); $name = $exif['FileName']; $height = $exif['ExifImageWidth']; $width = $exif['ExifImageLength']; $model = $exif['Model']; $exposuretime = $exif['ExposureTime']; $fnumber = $exif['FNumber']; $iso = $exif['ISOSpeedRatings']; $date = $exif['DateTime']; echo "File Name: $name<br />"; echo "Height: $height<br />"; echo "Width: $width<br />"; echo "Camera: $model<br />"; echo "Shutter Speed: $exposuretime<br />"; echo "F number: $fnumber<br />"; echo "ISO: $iso<br />"; echo "Date & Time: $date<br />"; var_dump($exif); This code produces the following:- File Name: brass jaw.jpg Height: 640 Width: 360 Camera: Canon EOS 550D Shutter Speed: 244/1000000 F number: 8000000/1000000 ISO: Array Date & Time: 2011:09:17 13:52:30 Which serves quite well apart from the ISO, which comes back as "Array". Now when I do a var_dump I see that ISOSpeedRatings returns as this:- 'ISOSpeedRatings' => array 0 => int 800 1 => int 800 What I can't work out is how to access the information from this - I know that the solution will probably be very simple, and that I will end up kicking myself, but I could use a little help. I am trying to use this weeklyReport1Boles.html: Code: [Select] <html> <head> <title>Weekly Report</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Weekly Report</h1> <p> <form action = "weeklyReport1Boles.php" method = "post" > <p> <input type = "submit" value = "Display the Report" /> </p> </form> </body> </html> TO PULL data from weeklyDataBoles.txt lines 1-8 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 THE RESULTING WEB PAGE SHOULD BE: Weekly Report TOTAL INCOME FROM PAINT CONTRACTS: $0.00 AVG DAILY INCOME FROM PAINT CONTRACTS: $0.00 NUMBER OF DAYS with NO INCOME: . MY PHP CODE IS: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); $total = 0; for ($count= 1; $count <=7; $count = $count +1) { $nextDay = fgets($weeklyDataBoles); $total = $total + $nextDay; } fclose($weeklyData); $avgDailyIncome = $total/7; print("<p>TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."</p>"); print("<p>AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."</p>"); print("<p>NUMBER OF DAYS with NO INCOME: $badDays.</p>"); ?> </body> </html> THE AVERAGES ARE BASED ON ONE WEEK OR SEVEN DAYS, WHY CANT I OPEN THE FILE AND GET THE PROGRAM TO READ IT, I AM A STUDENT AND VERY, VERY, VERY BAD AT THIS, MAKES ME CRAZY CAUSE I REALLY LOVE IT trying to create a simpleprogram that will read a text file and output information and calculations using the data in the text file. I have 4 radio buttons which represent an item Number. when one is selected the output form should print to a table the ID,Part,Count, Price, and the inventory Value= ($count * $price), can anyone tell me what i am doing wrong? This is what the .txt file looks like: AC1000:Hammers:122:12.50 AC1001:Wrenches:5:5.00 AC1002:Handsaws:10:10.00 AC1003:Screwdrivers:222:3.00 Here's what i have so far: Code: [Select] <?php $inf = 'infile.txt'; $FILEH = fopen($inf, 'r') or die ("Cannot open $inf"); $inline = fgets($FILEH,4096); $found = 0; //$ptno = //if (isset($_POST['AC1000']) || isset($_POST['AC1000']) || isset($_POST['AC1000']) || isset($_POST['AC1000'])) { while (!feof($FILEH) && !($found)){ list($ptno,$ptname,$num,$price) = split (':', $inline); if ($ptno == $id) { print '<table border=1>'; print '<th> ID <th> Part <th> Count <th> Price'; print "<tr><td> $ptno </td><td>$ptname</td>"; print "<td> $num </td><td> \$price</td><tr>"; print '</table>'; $found = 1; } $inline = fgets($FILEH,4096); } if ($found !=1) { print "Error: PartNo=$id not found"; } fclose ($FILEH); ?> So here is what I have going. #1 - My weather station software processes a file and enters variables and then uploads it as a php file. #2 - Currently the station also just uploads every file to the site and enters the data in the html, but I would rather have it only upload this one file and the other pages grab data from it and print it out. I have a few php scrips in there to preform certain functions (if temp <= 32 it echos that data in blue and so on) but would rather make most of it php so I have less files being uploaded every 5 minutes. This is what the station sends to the web, but I have no idea how to get the other pages to read it and input the variables from it. i have this script where the user enters their name and their favorite quotes. It adds their favorite quotes and their names to quotes.txt and prints out their name and their quotes on view_quote.php. I need to use a foreach() loop to print out the name and the quotes, but I'm confused about how to set it up. Here's my files. add_quote.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Add A Quotation</title> </head> <body> <?php // add_quote.php /* This script displays and handles an HTML form. This script takes text input and stores it in a text file. */ // Identify the file to use: $file = 'quotes.txt'; // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. if ( !empty($_POST['quote']) && ($_POST['quote'] != 'Enter your quotation here.' ) ){ // Need some thing to write. if (is_writable($file)) { // Confirm that the file is writable. file_put_contents($file, $_POST['quote'] . PHP_EOL, FILE_APPEND | LOCK_EX); // Write the data. file_put_contents($file, $_POST['name'] . PHP_EOL, FILE_APPEND | LOCK_EX); // Print a message: print '<p>Your quotation has been stored.</p>'; } else { // Could not open the file. print '<p style="color: red;">Your quotation could not be stored due to a system error.</p>'; } } else { // Failed to enter a quotation. print '<p style="color: red;">Please enter a quotation!</p>'; } } // End of submitted IF. // Leave PHP and display the form: ?> <form action="add_quote.php" method="post"> <p>Name:<input type="text" name="name"/><br /> <textarea name="quote" rows="5" cols="30">Enter your quotation here.</textarea><br /> <input type="submit" name="submit" value="Add This Quote!" /> </form> </body> </html>view_quote.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>View A Quotation</title> </head> <body> <h1>View My Quotes</h1> <?php // view_quote.php /* This script displays and handles an HTML form. This script reads in a file and prints a random line from it. */ // Read the file's contents into an array: $data = file('quotes.txt'); // Count the number of items in the array: $n = count($data); // Pick a random item: $rand = rand(0, ($n - 1)); // Print the quotation: print '<p>' . trim($data[$rand]) . '</p>'; ?> </body> </html>and the quotes.txt file is blank until the user enters their names and quotes. Im trying to get this done kind of quick so any help would be awesome. Hello, I am trying to read data from a text file but also adding up the 4th column for example 'name' 'more' '1.00' 'evenmore' so were the 1.00 is I want to add it up is there anyway ? I have 4 websites http://www.mercurymagazines.com/pr1/101/101395 http://www.mercurymagazines.com/pr1/169/16000 http://www.mercurymagazines.com/pr1/101/101396 http://www.mercurymagazines.com/pr1/169/16001 I am trying to write a program that will open each webpage one at a time, look for a unique word such as 'FREE' and if it is found the write the URL to a file, if not then no output and the next webpage is opened. I know this word exists only on one of the pages above (http://www.mercurymagazines.com/pr1/101/101396). When http://www.mercurymagazines.com/pr1/101/101396 appears last in the list located in source.txt the programs WORKS. When http://www.mercurymagazines.com/pr1/101/101396 appears in any other position such as first, or second, the program does NOT work. My head is sore from banging against my desk. Any assistance would be appreciated. <?php $file_source = fopen("source.txt", "r"); $file_target = fopen("targets.txt", "w"); while (!feof($file_source) ) { $url = fgets($file_source); echo '<br>'.$url; $raw_text = file_get_contents($url); mb_regex_encoding( "utf-8" ); $words = mb_split( ' +', $raw_text ); foreach ($words as $uniques) { echo $uniques; if ($uniques == 'FREE') { fwrite($file_target, $url); } } } ?> hey guys im tyring to read my directory (whole of the web server)...i want to be able to put the file name and root into an array...im just wanting to know whats the best function i need to do this please?...thank you $tracking_file_location = "../dispatch-manager/logs/tracking_file.txt"; $tracking_file = fopen("$tracking_file_location", "r") or die("Unable to open file!"); $tracking_file_size = filesize("$tracking_file_location"); $tracking_file_text = fread($tracking_file,$tracking_file_size); fclose($tracking_file); hi i tried to add this to my php file Code: [Select] <?php $xfile = @file('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $data = explode("::",$xfile[$random_num]); echo $data[1]; ?> i get no output i then tried just including the txt file like include 'banners.txt'; then everything in the txt file opens. and if i use fopen like this Code: [Select] <?php $xfile = fopen ('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $udata = explode("::",$xfile[$random_num]); echo $udata[1]; ?> i get this error Warning: fopen(banners.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/public_html/template/folder1/main.php on line 72 where as the txt file exist there anyone could help solve my issue? As per the client requirement he wants to read words from a file and want to insert them in database one by one . ie a confirmation is required whether he wants to insert is or not. I have developed the thing but the problem is when i am retrieving the words it asks for all the words. i will show u wat the problem is. My main query is i want to pause the exectution until user's input. Code: [Select] <script type="text/javascript" src="jquery.js"></script> <script type"text/javascript"> function show() { document.getElementById('form#submit').fadeIn(); alert("Abhinav"); } $(document).ready(function(){ $("form#submit").submit(function() { // we want to store the values from the form input box, then send via ajax below var word = $('#word').attr('value'); var synonym = $('#synonym').attr('value'); $.ajax({ type: "POST", url: "ajax.php", data: "word="+ word + "&synonym=" + synonym, success: function(){ $('form#submit').hide(); //$('form#submit :input').val(""); $('div.success').fadeIn(); } }); return false; }); }); </script> <?php $file=fopen("welcome.txt","r") or exit("Unable to open file!"); @$word=""; @$c=""; while (!feof($file)) { $c=fgetc($file); if(strcmp($c," ")==0) { echo "". "<form id='submit' method='post' name='submit' action='' >". "<fieldset> ". "<legend>Enter Information</legend> ". " <label for='word'>Word:</label> ". "<input id='word' class='text' name='word' size='20' type='text' value='$word' > ". " <label for='Synonym'>Synonym:</label> ". "<input id='synonym' class='text' name='synonym' size='20' type='text'> ". " <button class='button positive' type='submit'> Add Client </button> ". " </fieldset> ". " </form> ". "<div class='success' style='display:none;'>Client has been added.</div> ". "</div>"; $word=""; } else $word=$word.$c; } fclose($file); ?> Now what i want is after user clicks add client then only next insertion box must be shown. please check the attached image to see the output. Guys pls help me over this. Thnx in advance Where is the best to store the list of categories and menu? Obviously it is better to reduce mysql queries. From a plain list in file, we can create desirable list (menu) from an array. This is quite faster (though SELECT from an indexed table is fast too; but I do know if it is as fast as reading from a php file). Any idea how to code this to create the menu faster ? function GetStatus(){ $fd=read_file('s_status.sta'); list($perf, $msg, $rest) = explode('\n', $fd, 3); if(isset($perf) && isset($msg)){ return '<p class="status"><img src="/images/sta/'.$perf.'.png" /> $msg</p>'; } else { return ''; } } Hi everyone, Thanks for reading. I'm having a problem with my script, I would love to know why it's just stopping parsing and no errors are getting diplayed when I call this function. I'm using E_ALL, Highly annoying when still no errors come up... When the function is called the page stops parseing, The function returns nothing. The files content does like this: Code: [Select] ERROR This is an error Som other stuff I don't need hence $rest in the explode As you can tell it's a status file I checked the contents and it's all in the right format. Thanks in advance! |