PHP - Read Data From Text File
I need to search through a text file and output certain text.
My current script doesn't work well at all. Code: [Select] <? $file = 'flist.txt'; $handle = @fopen($file, "r"); $names = array(); $func = array(); $desc = array(); $nme; $fnc; $dsc; $s = -1; $e = -1; $n = 0; if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { if($nme == 0) { if(strpos($buffer,"<a name") !== false) { $nme = 1; $s = strpos($buffer,"<a name"); } } else if($nme == 1) { if(strpos($buffer,"</span>") !== false) { $nme = 2; $e = strpos($buffer,"</span>"); $num = $e - $s; $names[$n] = strip_tags(substr($buffer,$s,$num)); } } else if($nme == 2) { if($fnc == 0) { if(strpos($buffer,"<table style") !== false) { $fnc = 1; $s = strpos($buffer,"<table style"); } } else if($fnc == 1) { if(strpos($buffer,"</td>") !== false) { $fnc = 2; $e = strpos($buffer,"</td>"); $num = $e - $s; $func[$n] = strip_tags(substr($buffer,$s,$num)); } } else if($fnc == 2) { if($dsc == 0) { if(strpos($buffer,"<p>") !== false) { $dsc = 1; $s = strpos($buffer,"<p>"); } } else if($dsc == 1) { if(strpos($buffer,"</p>") !== false) { $fnc = 0; $nme = 0; $dsc = 0; $e = strpos($buffer,"</p>"); $num = $e - $s; $desc[$n] = strip_tags(substr($buffer,$s,$num)); } } } } } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); $n = 0; while($n < 100) { echo $names[$n] . "<br>"; echo $func[$n] . "<br>"; echo $desc[$n] . "<p>"; $n ++; } } ?> 4096 gets the data for each line, right? Well some of my data uses two lines. After all the searching is done I need it to output $names, $func, and $desc in plain text. Similar TutorialsFirst, my goals: - The user selects a text file on their local PC (or their local network drive) to process. - I want to read the file into an array and process it. I'm having trouble with this. Here is my code so far: <?php session_start(); $title='Import File v.10a'; ?> <!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" /> <?php echo '<title>'.$title.'</title>'; ?> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php require_once('navmenu.php'); echo '<h2>'.$title.'</h2>'; ?> <!-- comment --> <?php // Connect to the database $dbc = mysqli_connect($host, $user, $password, $database); $errcnt=0; $models=array(); //Init array $bullarr=array(); $model=''; $partname=''; $partsubname=''; $image=''; $ptype=''; //Product type in {type} tag. if (isset($_POST['cmdImport'])) //Save records that were changed. { $filename=$_POST['txtFilename']; //File on user's machine. $s='You are importing '.$filename; crDebug($s); //DEBUG if (move_uploaded_file($_FILES['txtFilename']['tmp_name'], 'upload/')) { $filename=$_FILES['txtFilename']['name']; $s='Received '.$filename; crInfomsg($s); } else { $errmsg='File upload failed. Error is '.$_FILES['txtFilename']['error']; crError($_SERVER['PHP_SELF'].' line '.__LINE__,$errmsg,true); } if (!(file_exists($filename))) { $errmsg='File '.$filename.' does not exist. Cannot continue.'; crError($_SERVER['PHP_SELF'].' line '.__LINE__,$errmsg,true); } else { } } //if isset($_POST['cmdImport'] ?> <!--------------------------------------------------------> <form action="<?php echo $_SERVER['PHP_SELF'].'?'.SID; ?>" method="post"> <hr/> <label for="cbxBrand">Pick one Brand</label> <?php $oldbrandarr=array(); //Init array. //Do query and loop here. //Show brands from zzbrands. $query = "SELECT bzz ". "FROM zzb ". "ORDER BY br ". ";"; //crInfomsg($query); //DEBUG crCreateSelect($query, 'cbxBrand', 'brand') ?> <p>Input file: <input type="file" name="txtFilename" id="txtFilename" value="" size="80" /> <br/><input type="submit" value="Import" name="cmdImport" /> </form> </body> </html> My problem is I get an error each time "File upload failed" which is displayed above when I try to do move_uploaded_file(). I'm not experienced processing text files. Can someone help me or point me to a website? One more thing, the subdir "upload" is located at the same level as this php file. That is where the uploaded files will go temporarily. Hi to all!! I am still new to php.. I need help in reading my text file and inserting it to mysql database. My text file contains 5 fields and has several rows.. The format of my text file: 1 romeo 8877 2010-07-07 abc1 2 nick 7686 2010-07-07 abc2 3 mark 5456 2010-07-07 abc3 4 karm 3432 2010-07-07 abc4 The first field is an INTEGER, the second third fifth fields are VARCHAR and the fourth field is a DATE. I am having trouble with my php code.. My code is this: <?php mysql_connect("localhost","root",""); mysql_select_db("personss"); $textFileName = $_POST['textFileName']; $myFile = "$textFileName"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); $person = explode("\n", $theData); $count = 0; foreach($person as $i => $line) { $nameParts = explode(" ", $person[$count]); $q = "insert into logged (id, name, num, datess, letters) values ('" . implode("','",$nameParts) . "')"; $rw = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); } ?> This code can insert to the database but it only inserts the first row and it loops the insert according to how many rows there are in the text file..For example in my text file there are are 4 rows, it inserts the first row: 1 romeo 8877 2010-07-07 abc1 4times..If there are 6 rows, 6 times the first row will also be inserted.. What i need Sir's is that i need to be able to insert the rows line by line.. if there are 4 rows, i need to insert them all in the database.. Please help me to fix the code. I very new to php and all I am simply trying to do is read the contents of a text file and echo it out on the screen. I have tried many things to see what I am doing wrong but it just simply isnt working for me. I know the server I am using has php enabled as well because I have tried a simple echo and it works fine. This is the code I am currently using. <?php $file = fopen(file.txt", 'r'); $read = fread($file, '6') echo $read; ?> also, I have tried this. <?php $file = file_get_contents('file.txt'); echo $file; ?> I have a file.txt on the server I am using in the same directory as index.php, I feel like this should be working but I get no result! Alls I have in the text file is a statement that says "hello world". I have the following text file: Code: [Select] 09/16/2011 - 09/16/2011 323780048 FedEx Ground Shipment Detail Report 09/22/2011 CAFE2472 Page: 1 TRACKING # RECIPIENT CD ZIP ZN CARRIER SVC BILL WGT COD DECL VALUE C GR CHG C SRCHG C NET ---------------- --------------- ------ --- ------- - --- -------- ---------- ---------- ---------- ---------- ---------- 561895962528473 97913 440607 4 Ground , RH 2.0 0.00 99.00 6.22 2.45 8.27 561895962528480 97928 352424 5 Ground , RH 17.0 0.00 99.00 9.89 2.45 10.60 561895962528497 97943 857164 6 Ground , RH 17.0 0.00 99.00 12.38 2.45 14.75 561895962528503 97955 193825 5 Ground , RH 4.0 0.00 99.00 7.17 2.45 8.42 561895962528510 6792 491069 3 Ground , RH 3.0 0.00 99.00 5.97 2.45 8.27 561895962528527 97967 030703 5 Ground , RH 1.0 0.00 99.00 5.75 4.10 10.06 561895962528534 97978 665429 4 Ground , RH 4.0 0.00 99.00 6.86 4.10 10.06 561895962528541 97992 371844 4 Ground , RH 1.0 0.00 99.00 5.51 4.25 10.22 561895962528558 98005 386108 4 Ground , RH 18.0 0.00 99.00 9.21 4.25 12.01 GRAND TOTALS COURTESY NET CHARGE 92.66 TOTAL WEIGHT(OF LBS) 63.7 TOTAL WEIGHT(OF KGS) 0.0 CSY DECL VAL SCHG 0.00 COURTESY DISCOUNT 12.52 COURTESY SPECIAL FEES 28.95 CSY FUEL SURCHARGE 7.27 PACKAGE COUNT 9 And I'm attempting to pull ONLY the tracking number and reference number (or order #) from this file. I've been able to get rid of the empty lines, get rid of the first few lines I don't need and grab just tracking and reference numbers , but I can' t figure out how to get rid of of the last few lines....here's my code: Code: [Select] $arr=file("/home/onest4/public_html/beta/fedex.txt"); $x=1; foreach($arr as $str) { if (trim($str) != '') if ($x > 3) { list($tracking,$ordernumber)=explode(" ",$str); echo $tracking; echo "<br />"; echo $ordernumber; echo "<br /><br />"; } else { $x++; continue; } } Here's the result: Code: [Select] 561895962528473 97913 561895962528480 97928 561895962528497 97943 561895962528503 97955 561895962528510 6792 561895962528527 97967 561895962528534 97978 561895962528541 97992 561895962528558 98005 GRAND TOTALS COURTESY NET CHARGE TOTAL WEIGHT(OF LBS) TOTAL WEIGHT(OF KGS) CSY DECL VAL SCHG COURTESY DISCOUNT COURTESY SPECIAL FEES CSY FUEL SURCHARGE PACKAGE COUNT Anyone help with this? Thanks! I have a PHP file that is executed via batch file very frequently for live updating. This is a sort of "sync" file for reading/writing to a MySQL database. I am able to get it functioning absolutely fine when executed manually via a web browser (and my echo debug lines output the expected information), yet when I run the same PHP file via the command line, it seems to just not be capable of opening any file for reading, so the equivalent variables that are correct when executed on a web browser are blank when echoed through the command line. Is there a different way of handling reading of files when running a php script via the command line, or should it function exactly the same as when run via a browser? For instance: $k = "0"; $line = file("examplefile.log")[$k]; echo $line; is there a php solution that will take the raw data from one file and paste it into another text file? I have a master file and a download file that always starts at quarter past midnight . this data needs to be pasted into the master file, in the correct place , possibly overlapping and replacing data that already exists. the length of the download file will vary but will always start at 00. 15 the two files are www.maidenerleghweather.com/download.txt and also www.maidenerleghweather.com/master.txt any help appreciated . can someone give me a push here? I've tried "file_put_contents" and "fputs" and neither one works for me. I'm running PHP on an IIS server and a windows hosting plan. PHP version is 7.3.1 I believe. here is my code: if ($validation = "true") { file_put_contents("ValidationsRedeemed.txt", $validationKey . "|", FILE_APPEND); //$handle = fopen("ValidationsRedeemed.txt", "a"); //fwrite($handle, $validationKey . "|"); //fclose ($handle); } else { //user entered a product key that is not recognized. tell them to try again. echo "<script>alert('The product key entered is not valid.'+'\\n\\n'+'Please try again.'); window.location.href='test.php';</script>"; } thanks! i have a text file that has spaces between each column. eg 12 12 13 22 34.5 10 13 18 88 32.5 12 33 17 23 22.3 (the actual data is weather data that accumulates a new line every 15 mins and is seen at www.maidenerleghweather.com/clientraw.txt ) each column represents a weather variable. i would like to use php to find the maximum values in each column and minimum values etc etc. how can i get the text data into arrays, so that i can then easily perform some simple stats on it? HOWEVER each line would NOT be an array. the first value in each line makes up array number one, second makes up two etc any ideas for a newbie beginner would be welcomed. Hi Everyone, I'm new to PHP freaks, and I'm hoping someone might be able to help me. I have written some code for a html page and used php to retrieve confirm whether or not data is in a text file. I also tried to write some code to insert the data supplied to my html page to the text file but it's not working. Can someone help me figure out what my issue is. I have attached my text file, and my php code as well. Below you'll find the code I used for my html page. Thank you for all your help, Phee <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Telephone Directory</title> </head> <body> <form action='SignGuestBook.php' method='post'> <h1>Sign Guest Book</h1> <hr> <br> <table align='Left'> <tr> <td>Name: </td> <td><input name='name' /></td> </tr> <tr> <td>E-mail: </td> <td><input name='email' /></td> </tr> <tr> <td><input type="submit" value='Sign' /></td> <td><input type="reset" value='Reset Form' /></td> </tr> </table> <h3></h3> <br> <h4></h4> <br> <h5></h5> <br> <h6></h6> <br> <h7></h7> <br> <hr> <a href="http://helios.ite.gmu.edu/~smohamu2/IT207/Lab%20Assignment%208/AddNew.html">View Guest Book</a> </form> </body> </html> [attachment deleted by admin] Hi I'm learning php and trying to write a script to extract registration information from a large text file. Sadly my meagre knowledge of php is letting me down a bit. It's a case of knowing what you want the script to do but not having the knowlege of how to 'say it'. So i was hoping that if I posted my code here someone could either give me a few pointers on where i am going wrong or suggest a better way. The text file data luckily has a recurring format as follows (for brevity i've only included one entry, which contains made up information): From: bella_done@yahoo.co.uk Sent: 02 February 2011 22:50 To: Jonny tum, patsy fells, dingly bongo Subject: Subject: Fun Run 2010 Categories: Fun Run Name: Bella Donna Address: 14 brondle avenue Postcode: cd83 1rg Phone: 0287343510 Email: bella_don@yahoo.co.uk DOB: 15/11/1945 Half or Full: Full fun run How did you hear: Took part in 2010 As you can see the data has a convenient boundary at the 'from' field and the colon (or so it occurred to me) so I created my script as follows: // the string being analysed $the_string = " From: bella_done@yahoo.co.uk Sent: 02 February 2011 22:50 To: Jonny tum, patsy fells, dingly bongo Subject: Subject: Fun Run 2010 Categories: Fun Run Name: Bella Donna Address: 14 brondle avenue Postcode: cd83 1rg Phone: 0287343510 Email: bella_don@yahoo.co.uk DOB: 15/11/1945 Half or Full: Full fun run How did you hear: Took part in 2010"; // remove all formatting to work with a clean string $clean_string = strip_tags($the_string); // remove form field entries from the data and replace with commas and a ZZZ boundary $remove_fields = array("Categories:" => "","Name:" => ",","Address:" => ",","Postcode:" => ",","Phone:" => ",","Email:" => ",","DOB:" => ",","Half or Full:" => ",","How did you hear:" => ",","From:" => "ZZZ","Sent:" => ",","To:" => ",", ); $new_string = strtr("$clean_string",$remove_fields); // split the data at the boundary ZZZ $string_to_array = explode("ZZZ", $new_string); $new_string2 = implode("</br>",$string_to_array); echo $new_string2; $myFile = "address_list.csv"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $new_string2; fwrite($fh, $stringData); fclose($fh); One major problem is when i write the new data to a csv file the csv contains spacings that cause it to be reproduced in a column form rather than as separate fields for each comma boundary. So can anyone suggest either a) a better way of extracting the data from the text file (doesn't need to be 100% clean and perfect) b) How can i stop the spaces in the csv (i thought i would have fixed this when i stripped the tags from the string at the start??). Any help would be greatly received by a newbie phper. It's my first shot at performing anything moderately taxing so if I've made some blaring oversites I would very much welcome your wisdom! Thank you Drongo I have a very simple system (few files) having simple articles (only title and a paragraph description) stored in single text files. I catch the data by Code: [Select] $data=file('article1.txt'); $title=$data[0]; $description=$data[1]; This simple system works perfectly, but the problem appears when increasing the number of files (e.g. more than 10,000 articles). This is a problem connected with the OS behavior for handling huge number of files. My first question: Is there theoretically a faster system (e.g. database-based) for retrieving data, comparing with retrieving from plain text file? Second question: what can be an alternative for this very simple system (no search query or additional field)? 1. XML: It has the same problem if storing in different files. 2. Mysql: It is very advanced for this system. 3. SQLite:I am thinking of this, but it still have advanced structure of SQL. 4. DB Berkeley: I am not familiar with Oracle at all, and I need to install something new on my server. Is it really worth of trying? 5. Anything else? In general, I just need fast reading the data. I have no idea how much the speed of these systems are different to determine which is worth of consideration. Thanks for sharing your idea. 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. Hello,
Trying to rearrange a data on the website. Looks normal when looking through preview on IE and chrome. But once moved to live website, the whole alignment changes from left to center , including the text that needs to show up. I am a newbie to coding and dont have a clue. tried puttng something together based on what i foud on the web. attaching screenshot and the code that i did. any help is highly appreciated. also attached is a screenshot of what happens when the php file is uploaded. Prior to doing that, the menu on the left is aligned properly and the assets that we have show properly.
What we are trying to do is rearrage the whole assets into different categories.
many thanks
Attached Files
portfolio.php 3.27KB
2 downloads
noalignment.png 11KB
0 downloads I am using apache web server on linux. I am using PHP for web designing. On web server, i want to show the configuration data by reading the ini file. I am creating this ini file from one php code itself. If this php code i run through linux terminal, the file is created with file and group owner as root.(i am having sudo rights on machine) Then if i try to read the ini file from my apache web server, it gives warning as failed to open stream: permission denied. I have tried changing the owner, and permissions to 777 of the file. Still it is not readable.
On the other hand, if i run the php code of ini file creation through web server, ini file is created with file and group owner as apche. and web server is able to read/ write the file.
But i want to create that file from root or some other user and later read/written by apache.
How to give this access permission?
Hi! I am having trouble reading a stream of data being sent to my PC via PHP5. It seems that my code stops when it gets to the read section and just sits there indefinately. I am somewhat new to PHP so a solution and explanation would be great! Code: [Select] <?php $host = "129.000.00.01"; // host IP address $port = 40000; // port to listen to // sets script execution limit set_time_limit(30); // 0 means unlimited execution time (constant running) // create UDP socket $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) or die("Could not create UDP socket!\n"); // reset socket for binding if(!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo "Failed to reset socket!\n"; } else echo "Reset socket successfully!\n"; // bind socket socket_bind($socket, $host, $port); // connect if (!socket_connect($socket, $host, $port)) { echo "Failed to connect to port!\n"; } else echo "Connected to port successfully!\n"; while (1) { echo socket_read($socket, 1024, PHP_NORMAL_READ)."\n"; } // close sockets socket_close($socket); echo "\nDone"; This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=352249.0 hi, i have the class here, and am trying to save the read column of the textfile to db. but unfortunately it's not being save, i don't know what's wrong... I also attached the textfile so you'll have an idea what am i trying to read from class Extractor { public $filehandler; public $data = array(); // set your db access details private $host = HOST; private $username = USERNAME; private $password = PASSWORD; private $dbname = DBNAME; public function __construct($file) { $this->filehandler = $file; } //prints col1 of textfile public function printcol1() { $fp = fopen($this->filehandler,'r'); while(($this->data = fgetcsv($fp,1000,",")) !== FALSE) { # $this->data[0]."<br />"; $this->savetodb($this->data[0]); } fclose($fp); } public function savetodb($data) { try{ $pdo = new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->username,$this->password); $pdo->exec("INSERT INTO test(col,id) VALUES ({$data},null)"); $pdo = null; }catch(PDOException $e){ echo $e->getMessage()."<br />"; } } } $file = 'iso3166.txt'; $shit = new Extractor($file); $shit->printcol1(); Hey guys, The script I use to generate images, more or less, works almost flawlessly. However, I keep experiencing a problem at random in my script when it comes time to call a JPEG or PNG file from an external server. A lot of the time it will work fine, but many other times it comes back with the error: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Cannot read image data Which causes the script to fail. Right now the images it say it cannot read are these: http://tiles.xbox.com/tiles/UT/EF/1mdsb2JgbA9ECgQLGwMfWSkgL2ljb24vMC84MDAwIAABAAAAAPkqMU4=.jpg http://tiles.xbox.com/tiles/Au/lM/1Wdsb2JgbA9ECgUAGwEfL1hTL2ljb24vMC84MDAwIAABAAAAAPpj6R0=.jpg http://tiles.xbox.com/tiles/6q/kv/1Gdsb2JgbA9ECgUAGwEfL1hSL2ljb24vMC84MDAwIAABAAAAAPsAqfU=.jpg http://tiles.xbox.com/tiles/tQ/UG/1Gdsb2JgbA9ECgUAGwEfV1gmL2ljb24vMC84MDAwIAABAAAAAPspBao=.jpg http://tiles.xbox.com/tiles/qp/Fx/0Wdsb2JgbA9ECgQNGwEfVitXL2ljb24vMC84MDAwIAABAAAAAP5ekbU=.jpg and as you can see, they work fine. So what's going on here? Is Microsoft somehow blocking the attempt? I can view the images fine in the browser, but sometimes it just won't work in the script. But like I said, it's not everytime. The line the errors comes up on are these: $lastxboxgames = imagecreatefromjpeg($lastxboxgames); $lastxboxgames1 = imagecreatefromjpeg($lastxboxgames1); $lastxboxgames2 = imagecreatefromjpeg($lastxboxgames2); $lastxboxgames3 = imagecreatefromjpeg($lastxboxgames3); $lastxboxgames4 = imagecreatefromjpeg($lastxboxgames4); I also have the script to echo the variables back to me when while it's running, so those urls up there came exactly from the script, so it's not that its getting the wrong URL, it just decides that the image isn't good enough. The script, generates my signature image below, and when any of the images that come from the xbox server return an error, they all do, including the avatar image in the top left which is a PNG. Any help is appreciated! <?php ini_set('display_errors', 0); function escapeArray($array) { foreach ($array as $key => $val) { if(is_array($val)){ $array[$key]=escapeArray($val); } else{ $array[$key]=addslashes($val); } } return $array; } $request_type=$_SERVER['REQUEST_METHOD']; $api_key=$_SERVER['HTTP_X_API_KEY']; $res=array(); if($api_key!=="643256432"){ $res['msg']="Failu Invalid API KEY"; echo json_encode($res); die; } // Connects to the orcl service (i.e. database) on the "localhost" machine //$conn = oci_connect('SCOTT', 'admin123', 'localhost/orcl'); $conn = oci_connect('test', 'test', '192.168.10.43/test.test.com'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $request=file_get_contents("php://input"); $request=escapeArray(json_decode($request,true)); print_r($request); // die; if($request_type=="POST"){//for creation of invoice echo $CONTACT_ID=isset($request['CONTACT_ID'])?$request['CONTACT_ID']:""; $INV_SERIAL_NO=isset($request['INV_SERIAL_NO'])?$request['INV_SERIAL_NO']:""; $NAME=isset($request['NAME'])?$request['NAME']:""; $INV_DATE=isset($request['INV_DATE'])?$request['INV_DATE']:""; $DUE_DATE=isset($request['DUE_DATE'])?$request['DUE_DATE']:""; $CURRENCY=isset($request['CURRENCY'])?$request['CURRENCY']:""; $SUBTOTAL=isset($request['SUBTOTAL'])?$request['SUBTOTAL']:""; $TAX_TOTAL=isset($request['TAX_TOTAL'])?$request['TAX_TOTAL']:""; echo $SHIP_SERIAL_NO=isset($request['SHIP_SERIAL_NO'])?$request['SHIP_SERIAL_NO']:""; $MASTER_NO=isset($request['MASTER_NO'])?$request['MASTER_NO']:""; $HOUSE_NO=isset($request['HOUSE_NO'])?$request['HOUSE_NO']:""; $shipment_data=isset($request['shipment_data'])?$request['shipment_data']:""; if($CONTACT_ID==""){ $res['msg']="CONTACT_ID is required"; } else if($INV_SERIAL_NO==""){ $res['msg']="INV_SERIAL_NO is required"; } else if($NAME==""){ $res['msg']="NAME is required"; } else if($INV_DATE==""){ $res['msg']="INV_DATE is required"; } else if($DUE_DATE==""){ $res['msg']="DUE_DATE is required"; } else if($CURRENCY==""){ $res['msg']="CURRENCY is required"; } else if($SUBTOTAL==""){ $res['msg']="SUBTOTAL is required"; } else if($TAX_TOTAL==""){ $res['msg']="TAX_TOTAL is required"; } else if($MASTER_NO==""){ $res['msg']="MASTER_NO is required"; } else if($HOUSE_NO==""){ $res['msg']="HOUSE_NO is required"; } else if($SHIP_SERIAL_NO==""){ $res['msg']="SHIP_SERIAL_NO is required"; } else{ $stid = oci_parse($conn, "Select * from FL_HDR_INVOICE where CONTACT_ID='$CONTACT_ID'"); (oci_execute($stid)); oci_fetch_all($stid, $out); if(count($out['CONTACT_ID'])==0){ $stid = oci_parse($conn, "Insert into FL_HDR_INVOICE (CONTACT_ID,INV_SERIAL_NO,NAME,INV_DATE,DUE_DATE,CURRENCY,SUBTOTAL,TAX_TOTAL) Values ('$CONTACT_ID','$INV_SERIAL_NO','$NAME',TO_DATE('$INV_DATE','YYYY-MM-DD'),TO_DATE('$DUE_DATE','YYYY-MM-DD'),'$CURRENCY','$SUBTOTAL','$TAX_TOTAL')"); oci_execute($stid); $stid_2 = oci_parse($conn, "Insert into FL_SHIPMENT_DATA (CONTACT_ID,INV_SERIAL_NO,SHIP_SERIAL_NO,MASTER_NO,HOUSE_NO) Values ('$CONTACT_ID','$INV_SERIAL_NO','$SHIP_SERIAL_NO','$MASTER_NO','$HOUSE_NO')"); oci_execute($stid_2); if(oci_num_rows($stid)>0){ $res['msg']="Invoice created successfully against this contact_id:".$CONTACT_ID; } else{ $res['msg']="Something going wrong please try again later"; } } else{ $res['msg']="contact_id must be unique"; } } echo json_encode($res); die; } I need to read json data inside an array. Please help correct my code.. i am trying to do an API. Hi there, I have an xml file which actually hold the currency conversion information which I downloaded from xe.com In the xml, the currency section snapshot looks like this: <currency> <csymbol>EUR</csymbol> <cname>Euro</cname> <crate>0.713</crate> <cinverse>1.403 </cinverse> </currency> this is the conversion of USD to Euro. And it tells how much is 1USD gonna be in Euros. i.e 1 USD = 0.713 EUR I have a product page on my website having the rates shown in USD. For the visitor is accessing the page from Europe it has to show the converted price in Euros. My application can detect the visitors country if hes accessing the page from Europe so that is not a problem. I just need to read the xml file and display the converted price based on the rates in the xml file. How can I read the xml file and output the price in Euros based on the rate. Thank you. All comments and feedbacks are always welcome |