PHP - Output Xml File
I am using SimpleXMLElement to generate an xml file.
I am having some difficulty with formating the file. Hoping someone can assist. (not having problem getting the data...just unsure when to use ->addChild, ->addAttribute and anything else) This is the structure of how the file needs to be appear: Code: [Select] <?xml version="1.0"?> <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:jwplayer="http://developer.longtailvideo.com/trac/" > <channel> <title>MRSS Playlist</title> <item> <title>Cardio routine with handweights</title> <media:content url="videos/set2_first_5min.flv" /> <media:thumbnail url="thumbs/set2_first.png" /> <description>side jumps, arm curls, leg squats, arm lifts</description> <jwplayer:duration>25</jwplayer:duration> <jwplayer:start>5</jwplayer:start> </item> </channel> </rss> Thanks as always! DK Similar TutorialsHello I need help with making a script. The script shall get the output of a jar file, by reading it from the stream. First it should start up the jar file. (exec I guess?) Then it should start to read from the stream and post it on the site. As a little "bonus", it would be nice if it could input things to the stream! Kind regards Worqy I just wrote a php page that pulls live data from a database and presents it in an XML layout. In Internet Explorer, I can Edit, Select All, then Copy-Paste and save as XML. The resulting XML works fine. In Firefox, I can click File, Save Page As, select Text Files, then name it as an XML. Again, it works fine as XML. So..... how do I skip the Copy/Paste (IE) or Save Page As (Firefox) steps and write the output directly to an XML file? I've played with stdout(), buffers, page capturing utilities (wget, cURL, httrack, etc....), but no luck so far. This creates a pretty intense page due to the amount of data involved (1.3+ MB). Any help is appreciated! I use this code: Code: [Select] <?php $databasehost = "localhost"; $databasename = "export_ajur"; $databasetable = "invoice"; $databaseusername ="root"; $databasepassword = "password"; $fieldseparator = ","; $lineseparator = "\n"; $csvfile = "1.csv"; $addauto = 0; $save = 1; $outputfile = "output.sql"; if(!file_exists($csvfile)) { echo "File not found. Make sure you specified the correct path.\n"; exit; } $file = fopen($csvfile,"r"); if(!$file) { echo "Error opening data file.\n"; exit; } $size = filesize($csvfile); if(!$size) { echo "File is empty.\n"; exit; } $csvcontent = fread($file,$size); fclose($file); $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error()); @mysql_select_db($databasename) or die(mysql_error()); $lines = 0; $queries = ""; $linearray = array(); foreach(explode($lineseparator,$csvcontent) as $line) { $lines++; $line = trim($line," \t"); $line = str_replace("\r","",$line); $linearray = explode($fieldseparator,$line); $linemysql = implode("','",$linearray); if($addauto) $query = "insert into $databasetable values('$linemysql');"; else $query = "insert into $databasetable values ('$linemysql');"; $queries .= $query . "\n"; @mysql_query($query); } @mysql_close($con); if($save) { if(!is_writable($outputfile)) { echo "File is not writable, check permissions.\n"; } else { $file2 = fopen($outputfile,"w"); if(!$file2) { echo "Error writing to the output file.\n"; } else { fwrite($file2,$queries); fclose($file2); } } } echo "Found a total of $lines records in this csv file.\n"; ?> And th output is: Code: [Select] insert into invoice values ('ID_PURCHASE_INVOICE','DOC_TYPE_NAME','DOC_EXT_CODE','DOC_NUM','DOC_DATE','WOVAT_AMOUNT','VAT_AMOUNT','TOTAL_AMOUNT','CONTRAGENT_NAME','CONTRAGENT_BULSTAT','CONTRAGENT_VATNUMBER','CONTRAGENT_POST_ADDRESS','CONTRAGENT_ZIP','CONTRAGENT_CITY','CONTRAGENT_AREA','CONTRAGENT_STREET','CONTRAGENT_MOL','CONTRAGENT_PHONE','CONTRAGENT_BANK','CONTRAGENT_BANK_CODE','CONTRAGENT_BANK_ACCOUNT','CONTRAGENT_EXT_CODE','CONTRAGENT_EMAIL','PAYMENT_NAME','DOC_MARKER1','DOC_MARKER2','DOC_MARKER3','DOC_MARKER4','DOC_MARKER5','DOC_MARKER6','DOC_MARKER7','DOC_MARKER8','DOC_MARKER9','DOC_MARKER10'); insert into invoice values ('108826','ДАНЪЧНА ФАКТУРА','1','111366','2/15/2012','160.08','32.02','192.1','ПРЕЦИЗ ООД','103565237','BG103565237','ВАРНА ГЕН.КОЛЕВ 38','','','','','','','','','','','','БАНКА','','','','','','','','','',''); insert into invoice values ('108830','ДАНЪЧНА ФАКТУРА','1','1002304974','2/15/2012','872.33','174.46','1046.79','ОМВ БЪЛГАРИЯ ООД','121759222','BG121759222','','','СОФИЯ','','','','','','','','','','БАНКА','','','','','','','','','',''); insert into invoice values (''); I need to remove last line ' insert into invoice values (''); . How to change my code? Ok so I have this script that I wrote and it works really good. I wanted to display the number of records in a table and since the db only changes once per day I thought I would put the couner on the back end. I have this script that changes the value of the text file every day. But I would love it if it outputted with commas.
Now it reads:
1234070
Want it to read:
1,234,070
Any thoughs?
#!/usr/bin/php -q <?php $username=""; // READONLY USER USED HERE AND AUTH'D ON LOCALHOST ONLY $password=""; $database=""; $dbhost=""; mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to connect to database please try again!"); $counthd=mysql_query("SELECT count(*) as total from HD"); $hdtotal=mysql_fetch_assoc($counthd); $dbcount = $hdtotal['total']; echo ""; $myFile = "dbcounter.txt"; $fh = fopen($myFile, 'w'); fwrite($fh, "$dbcount"); fclose($fh); ?> Edited by chadrt, 01 February 2015 - 07:26 PM. I am trying to make PHP output a file in html and using the following code. Code: [Select] <?php readfile("./1/index.html"); ?> ... but it isn't working. How would I get PHP to output a file as HTML? Given this script: <?php $file = file('info.txt'); $statelist = array (1=> "California", "Florida", "Illinois", "New York", "Texas"); foreach ($file as $line => $data) { list($state, $abbrev, $population) = explode('|', trim($data)); for ($x=1; $x<5; $x++) { if ($statelist[$x] == $state) { echo $state . ", " . $abbrev . " - " . $population . '<br />'; } } } ?> and this flat file (info.txt): Code: [Select] California|CA|36,756,666 Texas|TX|24,326,974 New York|NY|19,490,297 Florida|FL|18,328,340 Illinois|IL|12,901,563 This is what is outputted: Code: [Select] California, CA - 36,756,666 Texas, TX - 24,326,974 New York, NY - 19,490,297 Florida, FL - 18,328,340 Illinois, IL - 12,901,563 How can I sort the output by the index value of the "statelist array" so get this output: Code: [Select] California, CA - 36,756,666 Florida, FL - 18,328,340 Illinois, IL - 12,901,563 New York, NY - 19,490,297 Texas, TX - 24,326,974 Could ksort($statelist) be implemented? Hi guys <?php sleep(00); $handle = fopen("http://www.myurl.com/?bla=bla=bla" , "r"); fclose($handle); ?> How do i prevent this from outputing to a file on my server. I only need the url to be accessed to add a new row of data to my DB. Any Ideas? Regards Mark i have a php script: $sql5 = "select *,count(*) from rc_language_type_assoc_table group by language_type_id"; $result5 = mysql_query($sql5); //not correct $count5 = mysql_num_rows($result5); //not correct $myFile = "/home/rainbowcode/StatsFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $sql5."\n"); the above is not what i want, i want the actual result set of the select to print in my StatsFile how can i achieve this please??? I have a PHP script that does some work copying some files and parsing through the files. Then it creates an Excel file and sends it to the browser to download. So you user will see the standard popup asking to save or open the file. Well, I am using ob_flush to try and output text to the browser while it is working so the user knows something is happening. But whenever I add the ob_flush lines in, it just sends a bunch of garbage text to the browser instead of downloading the file. Anyone know a way around this? Thanks Mike Hi Hope someone can help me please. I have constructed an audio dictionary and have discovered an error now that I have added a few entries to the database. A user can search the database and can click on a result to be taken to the content associated with the entry he chooses. This is the search function; Code: [Select] $search=$_POST["search"]; //get the mysql and store them in $result $result = mysql_query("SELECT word FROM pro_words WHERE word LIKE '%$search%'"); //get the db content that is specified above if (mysql_num_rows($result) < 1) { echo "<br><br><h2> We didn't find anything. Sorry - we did look though.</h2>"; }else { echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr><td align="left"><b>Word</b></td></tr>'; echo "<br><br><h2>Success! Here's what we found:</h2><br>"; while ($r=mysql_fetch_array($result, MYSQLI_ASSOC)) echo '<h2><tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td></tr></h2>'; } You will see that content is displayed in a new file called word.php. This is relevant code from word.php Code: [Select] $query = "SELECT word,word_type1,sentence1,word_type2,sentence2,word_type3,sentence3 FROM pro_words"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<div class="colmask rightmenu">'; echo '<div class="colleft">'; echo '<div class="col1">'; echo '<p>Here are some example sentences that show how we use the word; </p>'; echo '<div id="small"><i> ' . $row['word_type1'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence1'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type2'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence2'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type3'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence3'] . '</p></div>'; } The problem is that every entry on the database is echoed in word.php whereas I would like only the entries for the word selected to appear. Thanks in advance for any help; do say if you need more info. Hi,
I need to create a landing page with a form. That form needs to be recorded somewhere instead of sent to email. I know I can write it to a SQL database, and then to an excel file. But I only need a temporary solution so I figured I'd just go straight to CSV.
Is this bad practice? What potential problems might I encounter other than security issues?
I'm trying to write a new csv file using the data from a large 1.4gb csv file. The problem is that its not working with the code I have below. It just hangs up when the size of output (tempfile) reaches 848661. Any ideas?
$file = "file.csv"; $file_number = 1; if (!$output = fopen($tempfile, 'w')) { unlink($tempfile); die('could not open temporary output file'); } $in_data = array(); $header = true; $row = 0; while (($data = fgetcsv($handle, 0, $delimiter)) !== FALSE) { if ($header) { $in_data[] = $headers; fputcsv($output, $headers, "\t"); $header = false; continue; } /* if ( ($row % 10) == 0 ){ error_log("sleeping on row: $row"); sleep(3); } error_log("checking row: $row"); */ if (!$val = getProductRow($data)) //this returns an array continue; $stat = fstat($output); error_log("Stat is: " . print_r($stat['size'],true)); if($stat['size'] > 9437184){ error_log("saving the $file"); fputcsv($output, $val, "\t"); error_log(__LINE__); fclose($output); error_log(__LINE__); if (file_exists($file)) unlink($file); error_log(__LINE__); rename($tempfile, $file); error_log(__LINE__); chmod($file, 0777); error_log(__LINE__); $final_file_name = $file = "file$file_number.csv"; error_log(__LINE__); $tempfile = tempnam(".", "tmp"); // produce a temporary file name, in the current directory error_log("creating the $file"); if (!$output = fopen($tempfile, 'w')) { error_log(__LINE__); unlink($tempfile); die('could not open temporary output file'); } error_log(__LINE__); fputcsv($output, $headers, "\t"); error_log(__LINE__); $file_number++; error_log(__LINE__); continue; } error_log(__LINE__); fputcsv($output, $val, "\t"); } Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. how to get the name of the file including a file from the included file, This one has me mixed up a bit.. I am trying to record site activity information from a common.php file using a user object. But since the file is included into different php files based on different situations I need a dynamic way of finding the file name that is including it. I could be over complicating things but right now this seems like the best solution other wise I'll have to rewrite the code on every page i write. Is there a function for doing this? Or if someone gets what I'm trying to do if they could point me to the direction of some more information on it. Thanks. hello guys..!!! am new to this phpfreak community...i hav faced some problem while getting on floating point nos addition..if i use echo (int)((0.1+0.7))*10; i am getting output as 7. If i remove (int), i would get output as 8..which is correct... for any other possibilities like ((0.1+0.2))*10 am getting correct output as 3..pls guys help me on this wid proper reason....waiting for solution.... Hi, This script lists all the contents of the dir it is placed in bar itself. Perfect for what I need. However, I want to output the results as xml and being new to php I really don't know where to start. <?php foreach (new DirectoryIterator('.') as $file) { if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) { echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename(); } } ?> I'd be thankful for the help Thanks in advance. help me. i have an index.php file in admin folder. this is the code inside the file: Code: [Select] <?php ?> Or any other code and i get output 0 , but if i echo something else then i get the string has output, help find out what is the problam please!!! Hi all, Is there a simple way to log the command output of a linux console? This command locks up my screen. It is a screen on an Aastra IP phone. $command = 'logsave /var/www/html/aastra/test.log ls'; shell_exec($command); Thanks! Hello. I'm looking for some help to make a script. The script should run a .bat file, and get the output from it. (The text from the console). Regards Worqy How do I got about outputing one row that can only hold one value? Any reason why the function below doesn't work? Code: [Select] <?php include "database.php"; session_start(); $name = $_session['outname']; function output_wins(){ $sql = 'SELECT * FROM account_info WHERE username ="' . $name .'"'; $result = mysql_query($sql); $wins = mysql_fetch_array($result); echo $wins['win']; } output_wins(); ?> Is there an easier way I can output this one row? |