Displaying Contents Of A Text File?
I'm trying grab the content of a text file and print it a web page. I believe that I should be using something along the lines of "file" or "fopen", but I'm not having any luck. Any thoughts or tips?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Read The Contents Of A Text File Into MySql Using PHP
New to this, have the basics, can build a form and such. My problem is I need to be able to open a file on a pc/s on the network, read the data character by character, check to see if a certain character is present, if it is, update the database and continue reading the file until it comes across the character again, updates the database and so on . . . .
Displaying Text With Include File.
Given this html code page; ======begin <html> <body> <!--#include file="outing.1.shtml"--> <form action="form.php" method="GET"> <input type="hidden" name="op" value="ds"> <table width="468" border="0" cellspacing="0" cellpadding="0"> <tr> <input type="hidden" name="id[1]" value="1"> <td>Name<input name="name[1]" type="text" size="30"></td> <td>Email<input name="email[1]" type="text" size="60"></td> <td>Phone<input name="phone[1]" type="text" size="15"></td> </tr> </table> <input type="submit" name="submit" value="submit"> </form> </body> </html> ===========end and this php code page; ==========begin form.php <?php if($_GET["op"] == "ds") { foreach ($_GET["name"] as $key=>$value) { echo $_GET["name"][$key] ."-". $_GET["email"][$key] ."-". $_GET["phone"][$key] ."-". $_GET["id"][$key]; $fp=fopen("outing.1.shtml","a"); fwrite($fp,$_GET["name"][$key] ."-". $_GET["email"][$key] ."-". $_GET["phone"][$key]); fclose($fp); } } ?> ========end Both of these are on my IP server, EV1. I would like the contents of 'outing.1.shtml' to be displayed hence the <!--#include file="outing.1.shtml"--in the HTML code.
Text File Displaying On Screen
I have a file that downloaded a CSV file for the user based upon some information gathered from the Database. My file was working fine until recently (I believe that my hosting company did something when they upgraded to PHP5). Everytime a user tries to download the file, it displays the contents on the screen. Here is what I have for my file handling. Am I missing anything obvious? when called, $filecontent is displayed to the screen... $downloadfile=$shownic."AttendeeRoster".time().".csv"; header("Content-disposition: attachment; filename=$downloadfile"); header("Content-type: text/css; charset=UTF-8"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".strlen($filecontent)); header("Pragma: no-cache"); header("Expires: 0"); echo $filecontent;
Formatting The Contents Of A Text Area Form Field
On my site I get users to enter a load of information in a textarea box, however when i save this data to my mysql DB and then retrieve it, it comes out without all the formatting, like new paragraphs and new lines. Can anyone tell me how you can capture the data entered into such a field with all the formatting the user has entered like new paragraphs etc?
Displaying Text
I am just screwing around a little and trying to display some text to the screen via a link to the text in a mysql db.
Displaying Text In PHP
I am trying to display a field in a database which is of type text in this fashion: Code: echo $row['thearticle']; However, the character ' is shown as ' i.e: "Britain's" will be displayed as Britain's . Do you what I need to do to solve this?
Output Variable Contents In Htm File From Php File
I have a PHP file. No MYSQL database. I'd like to have it open an .htm file and output the results in the php file to the .htm template. So, for example say there is a bunch of variables called: $make $model $year I want to open a .htm file and output the contents of $make, $model & $year in the htm format using variables in the htm itself. ie. {make} {model} {year} and it would import the contents of each into the corresponding tag.
Displaying Text From MySQL
I am working on a very simple news page for a website. I've setup a simple form that writes news to my database and the data is then displayed on my news page. I have gotten everything to work successfully but the content in the article loses all its paragraph formatting when I try to display it. I can use break tags to make the formatting show up but there has to be an easier way. This is the code I am using now, which I found on a tutorial somewhere and then tried to modify to work for my site: Code:
Displaying Long Text
I have a MSSQL 2000 database with survey data, the data field that contains the long data is varchar (8000). When I display the data it truncates the data to 255 characters including spaces. The following code is something like this: while($Results=mssql_fetch_array($SQL_Query) { echo $Results[0]."<br />"; } Is there something that I am missing?
Displaying Text Pulled From A MySQL DB
I have a web edit, delete and update script set up. its all working pretty much as i need except for one thing, the editing function. When an admin clicks edit beside an entry that page is resubmitted using $PHP_SELF and a variable is set. A check is then carried out in each form field to see if this variable is set, if it is set then a query is carried out and it enters the value of the query result for a table field as the value for the form field. You can see this in the code below. My problem is this: when the values of the DB are echoes out into the form fields they dont display correctly or they just display the first word until they reach the first space and then nothing else. PHP Code:
Displaying Text/html In Web POP Email
is it possible that message from web POP mail ( through sockets) appears as html (or text) if it is sent as html, not to appear like source file of the html document? I use web POP mail which is not mine and it displays without problem emails sent as text/plain but shows complete source with all tags if the email is sent as text/html, in other words, it´s useless and very hard to read for user.
Displaying Text While Page Is Loading
i'm trying to display text while a page is loading using a method similar to the following: <? ob_end_flush(); echo 'AAA<br>' flush(); sleep(10); echo 'BBB' ?> in this script, AAA and BBB appear at the same time - when the page has fully loaded - which is not what i want (i want AAA to appear and then 10 seconds later, BBB to appear). pursuant to the suggestions on php.net's entry for flush, i've also tried the following to no avail: <? echo 'AAA<br>' ob_flush(); flush(); sleep(10); echo 'BBB' ?>
File Get Contents()
I need to verify, (working on the HTML section of a mailer), If in my php.ini: allow_url_fopen is On Will file_get_contents(file URL) called as follow: $mailer->Body = str_replace('{MEMBER_NAME}', $member_name, file_get_content($htmlBody) ); Allows the file to become my email body? where $htmlBody comes from the DB...
Getting The Contents Of A File.
Is it possible to get the contents of a file; display the contents in a textbox; and edit the contents of that file. Then click a button and change the contents to the new updated file. The reason I want to know this is because I have programmers on my site and I don't want them to have access to the FTP or cPanel. They will jus enter the name of the file, click submit, be able to edt and replace that file. All without FTP or cPanel.
File Put Contents
looking to write to a file with out overwriting the previous data? is there a way to turn overwrite off with the file put contents?? im trying to keep a log of form data.
File Get Contents
i am trying the example of get_file_contents but i get the following error. what i want to do is get all the web page of google but the code wont work any ideas please cheers. Warning: file_get_contents() expects at most 2 parameters, 5 given in <?php $content=file_get_contents("http://www.google.com",FALSE,NULL,0,20); echo $content; ?>
Displaying Information From A Database In A Text Field,
I am trying to create an admin page, but before I get anywhere near that, I need to understand how to get data froma database to show up in appropriate form fields *text, textarea, etc...* I am able to get content from my database to show up in my template, now I want to create a page that allows a user to click on a link for which they want to edit the information (name, and bio) So I want that page to show up with a simple form, a text field displaying the name, and a textarea displaying the bio information, so that they can modify it and save it to the database. how do you get the information to show up in the form fields? Code:
Displaying First 50 Characters Of A Mysql Text Field?
I have been searching for hours on the php website for a function that will allow me to display just the first 50 chars of a mysql text field in a results table, but i'm having no luck. I need it to create a results page for a site i'm creating in php.
Displaying Text Fields On User Input
How would I echo a particular amount of text fields depending on how many the user selects from a drop down menu that I have already created. For example say the user selects 4 or whatever other number from a drop down menu how would I echo 4 or whatever the amount of text fields for a user to input text into? An example would be an airline website were you select how many people are travelling and then it echo fields for those people to enter their names.
Displaying Block Of Text From MySQL Database
I would like to create a details.php page that displays all my products. I understand how to get the title, price, description etc from mySQL. But my problem is how do I get a list of data? For example say I want to display the features of a product in point form (list). What is the best way to do this? How do most common websites do this? Code:
Deleting Contents In File With PHP
Hi, I need to get to a specific part of the file and delete a line so i can overwrite it with a new value. Example ... $Money = array( 0 => 10000, 1 => 932394, 2 => 3254#<Money> ); I need to change first choice "0 => 10000" and replace it with "0 => 7500" so it seems like they spent 2500 moneys I dunno if its possible but if it is please help, and thanks in advance FYI, the file is called testfile.inc and i dunno what that .inc means :P I just got it from a script i downloaded Further more, i want to do this change/replace through a form or a click using PHP.
File Get Contents Issue.
In folder WWW i have text file named news.txt. I'm calling file_get_contents("news.txt"); form index.php in the same folder. I got error: Warning: file_get_contents(news.txt): failed to open stream: No such file or directory in /home/www/index.php on line 14.
File Get Contents - Timeout
I Have googled and founds lots of references and examples of stream_set_timeout for fsockopen, but none showing how you apply a timeout to file_get_contents which I need to use in this case. Can anyone give me a sample of how to set a timeout on file_get_contents, as I understand that it can be applied to all PHP streams? This does not timeout after 2 seconds: $url ="http://www.mydomain.com"; stream_set_timeout($contents, 2); $contents = file_get_contents($url, false); Print $contents;
File Get Contents() Error
I made a PHP5 script that uses the file_get_contents() funtion and when I run the script, I get this error: Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration I called my host up and they said that it is a coding error, not a security or server error, Here is the code: <?php $address = "http://www.example.com"; echo htmlspecialchars(file_get_contents($address)); ?>
File Get Contents .limitation?
See this simple file_get_contents code <?php $link= 'http://www.example.com' $content=file_get_contents($link); echo $content; ?> I tried the code with these links: 1. http://www.example.com (...worked OK. Also tried google.com, yahoo.com,... all OK.) 2. http://www.example.com/buy/chess (...$content captured an error page instead of the result) 3. http://www.example.com/chessmotifs (...$content returned nil, ... totally nothing. This is the one I need the code to work btw.) Could this be because the site (in this case cafepress) uses some sort of scripts to generate their sub-pages? If yes, is there an alternatif method to "file_get_contents" that allows a page to generate fully before capturing?
Reading File Contents
I am parsing a file delimited by |. For some reason the content is displayed to the browser properly - but the loop is consistenlty outputting "one more row" of just the titles. Perhaps I'm going about it completely wrong: <?php $filename = 'books.file' $fp = fopen("$filename", "r"); while (!feof ($fp)) { $contents[] = explode("|", fgets($fp, 4096)); } fclose ($fp); $loop=1; foreach ($contents as $row) { echo "<b>$loop</b> -------------------<br>"; echo "<b>Reviewer</b>: $row[0]<br>"; echo "<b>Date</b>: $row[1]<br>"; echo "<b>Title:</b> $row[2]<br>"; echo "<b>Author:</b> $row[3]<br>"; echo "<b>Rating:</b> $row[4]<br>"; echo "<b>Comments:</b> $row[5]<br><br>"; $loop++; } echo "<a href="bookreview.html">Insert a new book review</a>"; ?>
If File Contents Equals
I'm trying to create a script that will check the contents of the file and will display a certain message if it does equal the correct value. How would I go about checking a files contents? I tried if (readfile("$file1") == "144.173.19.121") { echo "your ip"; } else { echo "doesn't work";}
File Contents To Variables
I have a file populated with information formated as on many lines: date: person:id:info:info2 please note that : is the seperater. How can I get this data into variables: $date:$person:$id:$info:$info2 I can open the file, display it's contents, even take the : out of it with this code I got from php.net: PHP Code:
Reading Zip File Contents
say i have a zip file - test.zip - with a file - somefile.txt - in it, whose contents are as follows: this is a test when i try running the following script on the above zip file, i get everything i should be getting, save for the contents of somefile.txt (example output follows the script): <? $filename = 'test.zip' if (($temp = zip_open($filename))) { while ($entry = zip_read($temp)) if (preg_match('/.txt$/',zip_entry_name($entry))) { print "file name = '".zip_entry_name($entry)."' "; print "file size = '".zip_entry_filesize($entry)."' "; print "contents = '".zip_entry_read($entry)."' "; } zip_close($temp); } ?> the output is as follows: file name = 'somefile.txt' file size = ཊ' contents = '' the output i would like and expect is as follows: file name = 'somefile.txt' file size = ཊ' contents = 'this is a test'
Need To Read The File Contents
I have a small problem.i need to read the file contents from the url.here is the desc of the problemthe file(local file with compelte path) name should pass thru url(no file upload option)so i need to read that file and store that content in the databasehere is the examplehttp://example.com/read.php?file="D://text.txt"Once i enter this url in the browser, i need to read that text.txt file and store the content of text.txt into DB.
Open File And Get Contents
I need to open a file and then echo the contents into a text area. I tried file_get_contents(), but it doesn't work, it isn't recognised as a function.. Any other way of doing this?
Delete File Contents
Can someone post some code to show me how to delete a file from a folder please? I need to delete a file first, and then upload something in it's place. Maybe a bit of code to slide in what i have already would work? Code:
Displaying Php Chart Text On My Host Using An Uploaded Font
Hi im trying to get a chart to display using php. I get an error at the moment when i use the function (or any requiring an uploaded font to be used): imagettftext($image, 6, 0, 0, $initial_point, $colorRed, 'Verdana', $initial_value); The error stems from the loading of the verdana ('Verdana') font file which IS uploaded and works locally but for some reason the script cant find the file on your site so its returning an error. Does anyonw know what what might be the cause of this? For example I am using a mac to work locally and then uploading to the php server which is linuz might i need to use diferent fonts or something on the server?
How Do I Open A Dir And Print The Contents Of Each File?
i can do it in perl with this $dirtoopen = "./database/"; opendir(DIR, "$filetoopen") or die "cannot open"; @files = readdir(DIR); closedir(DIR); foreach $file(@files){ $filetoopen = "./database/$file"; open(FILE, "$filetoopen") or die "cannot open"; $contents = <FILE>; close(FILE); ($addonname, $description, $submitter) = split(//, $contents); print "$addonname | $description"; } but how would i with php?
Overwrite File To Update Contents
I'm hoping someone can help me figure this little problem i am having with the following PHP script... i have registration form that a person can use to sign up for email, and when they submit there information, i have a script that is suppose to write to a text file the username and email address... however, is there a way to delete the contents of the text file or overwrite it completely with all the usernames and email addresses in the database(which was already there to begin with) plus the new person's username and email address???? the idea here is to have the most current info from the database be written to the text file when someone signs up for email... the following code snippet is the code that is suppose to place the new user's username and email address...
Basic File Get Contents Errors
I'm a newbie and have been learning PHP on and off for a while now. I am trying to rebuild my website after my host dissapeared along with all my sites data, and I am very nearly 100% complete to the point prior to data loss. However, one of the pieces of code written by another programmer is simply baffling me at the moment, and I think it may be due to the fact the code was badly written for a much older version of PHP compared to the version the site is on now with my new host etc The code should be searching for images from one of my suppliers websites but it runs and does nothing at all...I have checked the suppliers URL's and they match the code so what is going on here....am I missing something really simple?
Printing The Contents Of Each File In A Directory
I've been trying to create a PHP page that reads each file in a directory (txt, for example), and then outputs the contents of the file. The purpose for this is for someone advertising products for a website, so that he can use a form to describe the product, and then saves each entry as a new txt file. I then want the php to print the contents of the file. I've set it up so that it is html code, so formatting is not an issue. I've figured out how to read the contents of a single file, using file_get_contents. I can also display each file NAME from the directory. However, when I add file_get_contents into the loop, the php script wont run. Here's what I have so far: <?php $handle = opendir('sales'); if($handle) { while(false !== ($file = readdir($handle))) { print "$file <br>"; $contents = file_get_contents($file); print "$contents <br>"; } closedir($handle); }?> I've tried using seperate php entries and also had a play with readf and such, but can't seem to get anything to work. It seems like a common thing to want to do, and I've probably just made a small mistake somewhere?
Place File Contents Into Table On Page
Hi all. Am new to PHP and trying to get the following to work. I dont know if it is possible at all, and would appreciate any help. I have a folder called Books. It contains an htm page called books.htm which has some graphic elements on it. It also contains a file (either excel or csv, or tab delimited.... whichever will work best in this situation). This file contains two columns. 1st colums-1st row contains an image name (e.g. alice.gif). And the 2nd column-1st row contains a text discripition (e.g. Alice in Wonderland....bla bla..). And so on for the next rows. The folder also contains the actual 'alice.gif' and all images that are listed in the 1st column. What i am trying to achive is thus:- When the books.htm page is called. I want the table in the file to be recreated on the page under the existing graphic elements. In that table, instead of the image names in the first column, i want the actual image (which is present in that folder), to be planted there in that specific cell on the htm page!
Displaying File Path In File Input Field
i have file input field in a form like this: <input name="isbn" type="text" size="25" value="<?php echo $_POST['isbn'] ?>" /> <input name="image" type="file" size="25" value="<?php echo $_FILES['image']['name'] ?>" /> when i press "submit" button, the same page gets loaded... if my $_POST['isbn'] is empty, i want to have the file path on "file input field" to redisplay on that same field... it's possible in text input field but i don't know of a way to do it in file input fields...
File Get Contents Does Not Work When Reading Pages From 'mydomain.com'
Working on Linux, I created this script: --- $url = "http://www.mydomain.com"; $html = @file_get_contents($url, "r") or die("Can't open URL"); echo $html; ----- This script: - works ok on my PC box (PHP 4.4.5) with 'http://www.google.com' - works ok on my PC box (PHP 4.4.5) with 'http://www.mydomain.com' - works ok on my server (PHP 4.4.2) with 'http://www.google.com' - DOES NOT work on my server (PHP 4.4.2) with 'http://www.mydomain.com' Does anybody have any tip to find out why I can't read 'http://www.mydomain.com' on my server? Must I modify something on my 'mydomain.com' server (I manage it)?
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">)
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:
Displaying A File Path
Does anyone know how (in PHP) you can display the path of the current file? ex. (Home > PHP > Templates).I know you can do it in JavaScript, but I'd prefer to use PHP.
|