Format Text File After Fopen
I use “fopen” to access the text file (this is working fine). Then I want to format the results. I tried “fgets” but there is a “return” after each entry in the text file. "fgets" thinks this is a new record and puts the data on the next line. How can I bypass the "returns" and use the file as is.
Example of the text file:
Sold_To_Name............: XXXX XXXX
Ship_To_Name............: ZZZZZZZZZ
Sold_To_Address.........: XXXX XXXX
Ship_To_Address.........: ZZZZZZZZZ
Sold_To_City............: XXXXX
Ship_To_City............: ZZZZZZZ
Sold_To_State...........: XX
Sold_To_Zip.............: XXXXX
Ship_To_State...........: ZZ
Ship_To_Zip.............: ZZZZZ
Sold_To_Phone_Number....: XXXXXXXXXX
Ship_To_Phone_Number....: ZZZZZZZZZZ
This is how I would like to format text:
Sold to
XXXX XXXX
XXXX XXXX
XXXXX XX XXXXX
XXX-XXX-XXXX
Ship to
ZZZZZZZZZ
ZZZZZZZZZ
ZZZZZZZ ZZ ZZZZZ
ZZZ-ZZZ-ZZZZ
This my current programing:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Suggestion Needed On Data Storage Format In Text File
The project I am developing doesn't involves database. I want to parse the mailbox file (.mbx) and store the summary in the text file for fast retrieval and display of information in the Inbox page. The sugegsted format are as: #1 ID [4 bytes]: Subject [100 bytes]: To Address[100 bytes]: From Address[100 bytes]...etc... #2 Instead of preassining fixed size to variable (as actual data may be much less or can grew to more), we can store the values continuously, seperated by some unique seperator (#|#, *#*, ...) 1324#|#Hi, How are you#|#me@google.com#|#you@google.com#|# ... and so on Which of these will be the efficeint one (as there will be frequent insert/delete/update of the individual information, eg. set message as read ..., delete message ..., new message ...) Also please suggest on how to determine the variable size (100 bytes as in #1), and assign the size to the variable accordingly and read it (differentiate multiple variables) when required.
Format Number And Text
I want to format my id's in a sertan way however i am not sure how t approatch this problem. i want to write a function that formats a 0 to D000000. However i alsow wat to be eable to convert them back from D000000 to 0 to make calculations with it. For exaple adding 1 to create D100000.
Allow A User To Format Text...
I want to allow a page on me website to send an email to someone, but allow them the freedom to add images/format text etc. Is there a way this can be done using php, or is there an already existing php extension that will let me do this?
Function To Format Text As Html?
Is there a function in PHP that will format text in basic HTML automatically for you? I'm pulling an article piece of text from MySQL and on display, it doesn't break at paragraphs. I know the returns are there, because when I browse the data in PHPMyAdmin, the text is broken into paraphraphs. I'd rather not insert html into the text in MySQL as I may use this text for other purposes like print. Is there and html tag that I'm missing that would do this besides <pre>?
Mail() Plain Text Vs. Html Format
I have been testing the mail() code below using MS Outlook and Outlook Express and a hotmail account and the details sent are always in "plain text" format, which results in the information being nicely aligned (incidentally the e-mail contains order confirmation with lots of columns). However, my customer came back to me this morning to tell me that all is not well ! And rightly enough, when I looked at the snapshot he sent me he is receiving it in "html" format. What am I doing wrong ? Keeping in mind that I am a PHP greenhorn ... Can anyone help. Thanks in advance ! $headers = "From: info@somecompany.com "; $headers.= "X-Sender: <info@somecompany.com> "; $headers.= "X-Mailer: PHP "; $headers.= "X-Priority: 1 "; $headers.= "Return-Path: "."<info@somecompany.com> "; $headers.= "cc: info@anothercompany.com "; $headers.= "bcc: me@mycompany.com "; $headers.= "MIME-Version: 1.0 "; $headers.= "Content-type: text/plain; charset=iso-8859-1 "; if(@mail($to,$re,$msg,$headers)) { // tell them all was sent fine } else { // give an error message }
Format Result Text Using Passthru Of System
I tried to use the Passthru and System function to resolve some whois information. echo passthru('whois 62.69.168.12') .'<br>' -or- $whois = system('whois 62.69.168.12', $retval); It works fine, but all the result text is at one line. How can i format this output correctly ?
Fopen Ms Doc File
Is it posible to open a DOC file with fopen? If not is it psoible to open a RTF file in the same format as it is in word pad or MS word.
Problems With Fopen() And File().
Hi all, I'm trying to create a text login file. Problem is that sometimes the previously written user|time is not retained, and sometime the time is truncated and place on a newline as a new entry. This code should just open the file, build the current array based on appropriate amount of lapsed time, and then put the current user in the file along with the array. $u comes from the url via HTTP_GET_VARS, is valid, and should be put in as "new" each time this script runs. $tnow=date("Gi"); $in=file("TestingIN.txt"); $flag=0; $cnt = count($in); for ($x=0;$x < $cnt;$x++) { list($u_in,$time_in)=split("|",$in[$x]); if ("$u" != "$u_in") { //If they dont compare. if ($time_in>$tnow) { $tnow1=$tnow+240; //Compensate for different day. Midnight is 000!! if (($tnow1-$time_in) < 5) { //KEEP if less 5 min. $old_in[]=$in[$x]; $flag++; } else { //Do Nothing } } elseif ($time_in < $tnow) { if (($tnow - $time_in) < 5 ) { $old_in[]=$in[$x]; $flag++; } else { //Do Nothing } } else { //Do Nothing } }//END if they dont compare. } $newinfo="$u|$tnow "; $in2=fopen("TestingIN.txt","w"); $fp=fputs($in2,$newinfo, 40); for($y=0;$y < $flag;$y++) { $fp=fputs($in2, $old_in[$y], 40); } fclose($in2);
Location Of File (fopen)
This is something I always have trouble keeping straight. Assume I have a file tree as follows: /home /home/me /home/me/public_html /home/me/public_html/dir1 /home/me/public_html/dir2 My web pages are under either public_html or public_html.dir1. If I want to create a file under public_html/dir2, in php, is the correct command $FL = fopen("/home/me/public_html/dir2.filename", "w"); -or- $FL = fopen("/dir2.filename", "w"); What effect does "open_basedir" have on this - and how can I, as a PHP user be sure how this parameter is set.
Fopen(), Fsockopen(), File() Problems
I am trying to write a php script that will fetch the page data generated by another php script on another server and put that data into a string variable. The php script on the other server does some database queries and echoes a large amount of data. What I have tried so far is: $fp = fopen("http://www.otherdomain.com/folder/script.php?var=value", "r"); echo @fread($fp, 999999999); fclose ($fp); The above code will always time out the browser. PHP's max_execution_time is set to 10000, so it's not timing out there, only in the browser. It keeps going to a "Page cannot be displayed" error. I have also tried fsockopen(), but it seems that I can only enter a domain, like www.otherdomain.com, and not the file I am after. I have also tried: $string = implode ("", file("http://www.otherdomain.com/folder/script.php?var=value")); This one kinda works when the returned data is small, but if it is large it gives a wierd error, something like: Warning: '/htdocs/temp/myscript.php' Success - file("http://www.otherdomain.com/folder/script.php?var=value") If anyone can help me with this I would be very happy. I have looked at most posts about this subject and none were able to help so far.
Fopen Scan If File Exist
I'm using fopen to write binary data to a file. Now I want to scan if a file exsist before writing. How do I know if a file exsists? if (fopen (existing_file)) fopen wil give true if (fopen (non_existingfile)) fopen will also give true? (I got that out of the manual) Only if error occours there will be a false. So how can I find out if the files is opened or created?
Remote File Blocked With Fopen?
For some reason, google doesn't let me open up it's search query with fopen? Is there an alternate way to get it that I am unaware of? Code:
No Such File Or Directory Error - Warning: Fopen
I'm parsing out several XML files (*.rdf) from various news sites, and dumping the data into a MySQL table so I don't have to get it but once every 2 hrs. or so. (My site pulls from the DB, and a cron updates the db every 2hrs.) Everything parses really nice, unless I get a: <error> Warning: fopen("http://somewhere.com/unreachable.file", "r") - No such file or directory in /home/me/myfile.php on line 15 Warning: Supplied argument is not a valid File-Handle resource in /home/me/myfile.php on line 19 </error> The main problem with this error, is that it will appear no matter what (even the @ suppressor) and throws the page out of whack. On top of that, my parser doesn't get the failsafe errors I've tried to use, b/c PHP is barfing on the above error and not telling the rest of the script. So, my DB will be updated with NULL info! I'm currently using fopen() , but have read about the socket option to test the site, but I don't think they would work b/c they're not page specific, rather site specific.
How To Strip Out Unnecessary Lines From Php Fopen File
I have a file that is stored on a computer on my network which i access using fopen for reading. The localpath to the file is http://www.example.com/output.txt The contents of this file is updated once in a while and basically I need a php script that will open this file, read it and then remove certain things and then save a copy locally. The contents of this file looks as follows: Volume in drive C has no label. Volume Serial Number is A85F-F7AD Directory of C: est 10/01/2007 01:36 PM <DIR> . 10/01/2007 01:36 PM <DIR> .. 10/01/2007 01:32 PM <DIR> abc 10/01/2007 01:32 PM <DIR> 123 10/01/2007 01:32 PM <DIR> def 10/01/2007 01:32 PM <DIR> 456 0 File(s) 0 bytes 7 Dir(s) 68,797,751,296 bytes free i want to get rid of the first 7 lines of the file and the last 3 lines. and then on each line i want to get rid of everything before the <DIR> including the <DIR> aswell.
Using Fopen() To Create New File - Works For A Few Then Just Doesnt
I am currently working on a content management system where a user can fill in a form (title, keywords, link text etc. - all the initial attibutes), which when submitted, will go onto create a web page. The code is as follows: $html = "<html> <body> <p>Hello World</p> </body> <html>"; $handle = fopen($_SERVER['DOCUMENT_ROOT']."/path/to/folder/".$filename, "w"); fwrite($handle, $html); fclose($handle); Pretty basic, I think. I works for a few and then it just stops. I get no error to say that 'could not create file' or 'file not found', it just submits. Any reason for this? I have tried searching the C: drive for the file but it cannot be found. At the moment Im trying to figure out when it actually occurs but for some annoying reason, it seems to be working now. I would prefer to be assured that it wont occur again so just thought I would still post something here just encase this problem is a known one. Is fopen() the best solution for creating files? I was aware that it was used to open an existing file but create one (?). Is this what it was intended to do? Im sure it is, but its new to me.
Reading Remote File With Both Fsockopen And Fopen
Whenever I try to read a remote file I get the following two warnings: Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/narutof2/public_html/download.php on line 55 Warning: fsockopen() [function.fsockopen]: unable to connect to www.example.com:80 in /home/narutof2/public_html/download.php on line 55 There the same for both fsockopen and fopen. I tried using real files, same errors occur. I found a post about this online but it doesn't look like they were able to resolve it.
Fwrite() Returns False After A Successful Fopen($file, 'a+b')
I wrote the function below as part of a larger class. The fopen stage works, and, as according to the documentation at www.php.net/fopen that succesfully creates a new file. The fwrite stage returns false, however, on the first time the function is run, but returns true the second time it is run. Can anyone suggest why fwrite only works the second time? There are no entries in the apache log, even with error reporting fully turned up (note that I have removed @ from infront of each function, so would expect something). --- function writeDataToFile ($data, $file) { # Attempt to open the file in read+write mode if (!$fileHandle = fopen ($file, 'a+b')) {return false;} else { # Attempt to write the data #!# For some reason this returns false just after the first time trying to create the file if (!fwrite ($fileHandle, $data)) {return false;} else { # Having written to the file, close it fclose ($fileHandle); # Return a positive result return true; } } }
Warning: Fopen(): URL File-access Is Disabled In The Server
I ve been trying php script sent by rchaplin and all goes ok automatically appears a new file copied after script execution but it appears a messaje like next one: Warning: fopen(): URL file-access is disabled in the server configuration in /home/freehost/t35.com/n/a/nacion/p/new.php on line
Read And Display Japanese Text From Text File
I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with the same problem. The plan was to make a script to read and display japanese text. I will use it for making a japanese proverb script and for a japanese language study script. Method : I wrote a simple kanji text file (saved with UTF-8 encoding) I wrote a simple PHP script to display the file contents (saved with UTF-8 encoding) I specified the content-type header for the HTML page : <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> *** All files have the same encoding. *** UTF-8 supports japanese characters. and it works! this is my PHP (and HTML) script : <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>PHP : Japanese Text File Read : Exercise 1</title> </head> <body> <?php $filename="japanese.txt"; //open file $fp = fopen($filename,'r'); //loop through each line in the file while($line=fgets($fp)) { //output current text file line print $line."<br>"; } //close file handle fclose($fp); ?> </body> </html> I know it's a very simple script, for testing purposes only. It displays the contents of the japanese text file line by line. The key was to save all files in the same encoding (I used UTF-8) and to specify the encoding / charset in the HTML header (<meta http-equiv="Content-Type" content="text/html; charset=utf-8">)
Fopen - Append Works, Write Fails (but File Is Truncated)
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good) free hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the PHP info below shows ... Test it at: http://home.no.net/moldevbk/fopen-test/?mode=w (write - fails) http://home.no.net/moldevbk/fopen-test/?mode=a (append - ok) http://home.no.net/moldevbk/fopen-test/p.php - PHP info http://home.no.net/moldevbk/fopen-test/fopen-test.phps - source code of test script. I have searched the web and usenet, but not found this problem mentioned before. I do realize that I can work around the problem by truncating the file first and then appending to the empty file - but that is ugly as ...
$graph->Stroke() Genetates A Bmp Format File!
After i generate an image "on-fly" with gd function i tried to save the image and i was suprised to see that the image generated is BMP!! so a simply graph took 200k or more... I wish to know if that format makes the image elaboratio more slow adn how it is possible to generate with stroke() PNG format.
How To Format Data In A File Which Will Be Open In Excel?
I am trying to generate a file with php from a database extract that i would like to be open in excel. What i need is to format the content of the file in CSV i guess. The 'fgetcsv()' can do the job by formating the content of an existing file. Is there an other option than to create a file with my database content, save it on the server and open/format it with 'fgetcsv()'?
Looking For A CVS File Format Manipulation Utility Or Code
I've used desktop software that allowed import or eport of data in comma deliminated format and had a gui interface that easily allowed columns to be reordered and deleted. I could do this in spreadsheet but is there a stand-alone utility of code I can imbed into an app for this?
Limiting Allowed File Format For Upload...
I don't really know much about php and needed to make a web contact form for a client where the user can upload images which are then sent as an attachment with the resulting email. I kind of cheated and bought a bit of software which creates the script for you. This works great, but I am concerned about people uploading things other than images - especially after seeing this thread: [URL].... Now, obviously there is a bit of script in one of the replies which addressed my issue, but I don't know enough about php to adapt it for my own script. Therefore, I was wondering if someone would be so kind as to point out where I need to make changes and what those changes would be. I need to allow only common image files and to disallow any of the nasty stuff described in the above thread. I have created this stripped down script with my software, which addresses the essentials of uploaded image and resulting email to which it is attached, plus a section which deals with errors, http referers and stop words for security. The actual script includes more fields, but I thought it would take up too much space! PHP Code: .....
Remove Text Header In Text File
I have been having trouble removeing two header lines at the top of my txt file. You will see in my code the different things I have tried but with no luck. Below I posted my script and data. I am doing a few other things in my script as you will notice but this is the only thing I am having troble with. Code:
Problem With Fopen And File Location, Simple Problem?
I have a PHP script that uses fopen("$filename"); I want to use this script in multiple directories on my site, however, it seems like I have to have a copy of "$filename" in every directory to get it to work. I have tried fopen("/filename") fopen("http://mysite.com/filename") and none of these seem to work, I always get a file does not exist error, until I drop the "filename" file into the directory where the script is being run. Any ideas how I can make this work so I don't have to have dozens of "filename" all over my site?
Text Box To .txt File
does anyone know how to make a text box in php that when submitted, it writes to a .txt file?
Text File Display
I have a number of SQL reports that create standard 132 column text files. The user wishes to view these files in a browser in addition to their daily printing on a laser printer. I can handle directory structure, etc with PHP but I would like to know what is the best way of displaying these text files on screen. We can select them but they are very plain. Is there a TXT2HTML ot TXT2XML type tool that can display headings, bolding, etc without too much difficulty. I would rather not reprogram the reports as there are hundreds of them, and embedding HTML would not be an answer as they need to be printed on a regular laser.
Saving To A Text File.
I haven't been able to find a way to save the results of a MYsql query into a tab delimited text file... Anyone know how to do this, or if there are any already written scripts out there that perform this, or a similar function?
Database Row To Text File
I need to get the contents of a MySQL database field into a text file, and write the file to the server. I can not seem to get any filesystem functions to work, because it tells me I do not have permission to do anything. I am on virtual hosting, so it seems easier for me to try to FTP files to my own server. Perhaps you guys can give me some pointers, this is kind of the idea I am running on:
Writing To A Text File
i have a text file with the number 250 in it and nothing else. i have a variable which is worth a 300. How can i add this value to the one in the file so that the value of the file has changed to 550?
Text File Into Variable
I'm setting up an script that will send mail to an address given by a user. The problem is that the body of the e-mail varies depending on a few responses that the person gives, and writing out like 1000 lines of code just to get each of the outcomes covered is not my idea of fun. My question is, is there any way to make a variable in PHP the contents of a .txt file so I don't have to have that big of a script?
Retrieval From A Text File
How would I go about retrieving info from a text file into a variable field? If the data is stored in more than one line or separated by line breaks?
Php File Showing As Text
I have tried to upload a tested PHP file to my server and every time it gets accessed it displays itself as text and does nothing that its supposed to...
Form To Text File
I don't know anything about PHP, ASP, CGI, all I can do is use Microsoft FrontPage to edit html. But I have been searching the internet for a script (any laguage) that can send an html form to a text file. But I need the new data to replace existing data in the text file every time I submit new information. Is this possible in PHP or any other language? I’m hosted on a UNIX server with php installed and I have access to my cgi-bin and all I need is this little script to complete my website.
Str_replace From Text File
I want to use a text file with words that needs to be replace. $theentry = str_replace(array('word1', 'word2'), '*****', $theentry); Instead of array('word1'),'word2') i want textfile.txt to be opened with all the words to be replace with ******.
Text File Instead Of Database?
Does anyone know a script that I can use to manage members of my website (preferably with a control panel-type interface) but without using a database? I read on hotscripts.com of one that uses text files instead, but the link says that the site is no longer offering that file. If someone could help me it would be great, as I know nothing about scripting. By control panel, I mean a page that I can go to on my site (not open to the public) that I can use to Admin the users. I would like it to go something like this: (this is what was offered at hotscripts.com) New Members Username: New Members Password: New Members Name: New Members E-Mail Address: And optionally (I don't really need it, but if its possible, hey why not) a place for me to put in an admin username and pass to get into the page mentioned above. I would also like to be able to implement this script on my main page (see here for what I mean.
Exploding Text File....
I want to put a text file into a form field, and then submit it to a page that will split up the text file on two criteria and then loop through each split result inserting new db records. A sample text file would be: question 1;option1;option2l;option3 question 2;option1;option2l;option3 question 3;option1;option2l;option3 I need to split it on blank lines and then again on the options so that my insert would be insert questionname, option1, option 2....into questions. Can someone help please. I know I can use explode, but unless I am missing something then its just not working for me.
|