Delete A Line In PHP
What i want to do is to open a file read the file Select a particular line from the file and delete that line and close the file. How to do it in PHP.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Delete Last Line Of File
I have a flat file on the server which I append to from a HTML web form. I need to delete the last line of the flat file before I append though. How do i do that? I have the following code. I'm not sure if it's correct. $pattern = "</member>"; // what I want to look for. $ora_books = preg_grep($pattern, file('/path/to/your/file.txt'));
CLI ( Command-line ) PHP Displaying Source Code In-line When Programis Executed
I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. Everything has been running flawlessly without problems. Very amazing to use VMware, it has worked beautifully. uname -a Linux xxxxxxx 2.6.13-15.8-default #1 Tue Feb 7 11:07:24 UTC 2006 i686 i686 i386 GNU/Linux php -v PHP 4.4.2 (cli) (built: Feb 7 2006 20:13:29) Copyright (c) 1997-2006 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies php -m [PHP Modules] bcmath bz2 calendar ctype curl dbx dio domxml exif ftp gd gettext gmp iconv mcrypt mssql mysql ncurses openssl overload pcre posix session shmop sockets standard sysvsem sysvshm tokenizer wddx xml yp zlib When I run the following program from the command line it prints out the source code as well as the output from the program. I run other PHP programs on the command-line and this doesn't happen. It's really peculiar. The error output is below. I copied this off of php.net, and have modified it only slightly to allow command-line input. I was trying to find a CSV solution, which I ended up finding elsewhere, but am curious why this program would error out the way it does--have I misconfigured something? My php.ini is basically unchanged, if at all. I think I might have set the path to mysql but that's about it. When I run this program from the web it works without error. <?php if ( $argv[0] ) { $file = $argv[0] ; } else{ $file = $_GET['file'] ; print "<font face=arial> " ; } $row = 1; $handle = fopen("$file", "r"); while ( ( $data = fgetcsv($handle, 1000, ",") ) !== FALSE ) { $num = count($data); print "$num fields in line $row:<br> "; $row++; for ($c = 0; $c < $num; $c++) { print "$data[$c]<br> " ;
How To Return Just First-line From A Multi-line String Of Text?
I've been looking through the manual for string commands, and I haven't had success in determining the proper call for this, if there is one: Let's say I have a text string with hard-carriage returns in it: "The lazy brown fox ran down the road to the store and bought some eggs to bake a cake and serve dinner for all his friends." So if that string value is in "x", how can I tell it to return JUST the first line: "The lazy brown fox ran down the road"
Open File, Add Line At Beginning, Remove Last Line
I'm trying to open a file, write one line at the very beginning, and delete the last line. Right now I'm stuck at trying to open the file and write a line at the very beginning. Here's my code: $f="myfile.txt"; fwrite(fopen($f,"a"),"Add This Line"); I know I'm opening this file in append mode, where it will always write my text at the end of the document, but I can't figure out any other mode that would allow me to open an existing document and not delete everything that is already in it.
Reading Files Line By Line Backwards
I'm new to PHP, and I'm trying to write something for my website. I have coded a game together with a friend of mine, and as with all new games and programs, it's full of bugs. What I would like to do, is write a page where everyone can post bugs (I have this part, not that hard). Then it should be read from the textfile they're all in, but backwards, so the newest bugs at the top of the list. Also I would like to add an option for me to login using a username and password, to mark bugs as fixed, or delete certain bugs from the list. I have the user part covered too, but I don't know how to delete a single line in the textfile.
PRINTing A Large String – Line By Line Or In One Go?
In many of my apps I read in a HTML file line by line, do some string substitutions and then print out the file line by line to the browser, for example: $fragment_to_show_handle = @fopen("page.html", "r"); while ( !feof($fragment_to_show_handle) ) // while not end of file { $line = fgets($fragment_to_show_handle, 1000); $line = str_replace("%pics%", $pics, $line); // do the substitutions one at a time $line = str_replace("%currency_select%", $currency_select, $line); // etc print "$line";// print the line to browser } fclose($fragment_to_show_handle); Alternatively, in another app I have done this: $home_html = implode ('', file("$fragments/home.html")); $home_html= str_replace("%applet_code%",$applet_code,$home_html); $home_html=str_replace("%pics%",$pics,$home_html); // etc print "$home_html"; Assuming the total output to the browser is the same, say about 20-50k, which approach is more efficient in a php/apache/unix environment in terms of speed and least server load?
Read Text File Line By Line
I have been given a textfile which contains data on 1000 businesses. Each line contains a name and a code which are seperated by a comma. The code below allows me to display the entire textfile but I want to read in the values from each line and store these in a database. $filename = "businesses.txt"; $fileToOpen = fopen($filename,"r"); $content = fread($fileToOpen, filesize($filename)); $content = nl2br($content); fclose($fileToOpen); echo($content); Does anyone know how I can read the data in line by line so that I can store it in a database.
Remove Certain Line Write Certain Line
I read a file and check wether the name of the thing they are rating is in it. Now, I want to make it that if it is then copy the line already in the file (in array) remove that line from the file add some values together then put it back in and the same place it was in ofr maybe just the end.
Read A File Line By Line
Is there a function to read a file line by line in PHP, i.e. the way you do in Perl like <file_handle> ..... Note that i don't want to use the file() function.. that read entire file into an array and is not suitable when you're reading large files.
How Do I Get The Line Current Line Number ?
For error handling, is there a way to determine what line number the code is on, or do i just reference that line when im calling the error handler ? Actually the custom error handler is i suppose called by ph itself, so you arent suppose to call this directly, rather if you want to explicitly trigger an error, you should use trigger_error, correct ?
Echo Line By Line
this code gets all existing users: function getAllUsers() { $users = shell_exec('sudo /var/www/ftpadmin/./getUsers'); $output = shell_exec('cat users'); echo $output; } now echo $output gives something like: user1 user2 user3 user4 user5 ... now I would like to echo this line by line like this: <option>user1</option><option>user2</option><option>user3</option><option>user4</option><option>user5</option> without line breaks!
Read Line By Line From TXT
I know how to read form a txt file and then display that data But Now suppose that i have a txt file with data in the form as below: 1.AAAAAAAAAA 2.BBBBBBBBBB 3.CCCCCCCCC 4.DDDDDDDDD what i mean is in different lines. Now i want to display the data in different table data (<TD>) in HTML. ie for every line there should be a new TD added.
Delete From $var
Is it not possilbe to have a variable for the table name in a delete statement (mysql database). inside an if this button is hit statement I have: $sql = "delete from $type where id_num='$number'"; mysql_query($sql); echo "$sql"; when it echos $sql it doesnt have the $type var where the table name should be, it just leaves that blank.
Delete A Row
This should be simple enough but for some reason it's not working. The $name is a number which is being posted across when the user clicks submit. I want the PHP to then access the Database with this number and use it to delete the staff ID (which is a PK). With this code I get the error: Warning: ociparse(): supplied argument is not a valid OCI8-Connection resource in /homedir/ilex-s01/jmsuther/public_html/DeleteStaff.php on line 16 Warning: ociexecute(): supplied argument is not a valid OCI8-Statement resource in /homedir/ilex-s01/jmsuther/public_html/DeleteStaff.php on line 17 ; The code is: $name = $_POST["staffnodelete"]; IF ($staffnodelete=="" ) {print "You selected $name - for deletion ";} putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin"); $con = OCILogon("username","password","10g"); $query = "DELETE FROM staff WHERE staffno = $name"; $query = $query_post [$name]; $stmt = ociparse($conn, $query); ociexecute ($stmt);
How To Delete Fields
I would delete with php, all record of a table mysql where the seven left chars of the field is equal to the data in input($seven_chars). I have used the the belowe istrucrion but it do not work.how can I do? mysql_query ("DELETE FROM my_table WHERE substr(myfield,0,7)=$seven_chars");
Can't Delete Cookie
Right I am quite new to php but have managed to create a simple log in/log out thing with cookies. All was working fine and as expected until I added a new section of the site. The new section stores another cookie (latest message user has read) so that next time they visit the site it will highlight the 'new' messages. However since adding this I can no longer log out.
Can't Delete Cookie, Help Please~
Page1: <? setcookie("book_id", $book_id ); ?> Page2: <? setcookie ("book_id", $book_id, time() - 3600); ?> Can't delete cookie at once but reload page 2 two times how to delete $book_id cookie without reload?
Cookie Won't Delete
I'm trying to setup a simple user authenication for my site. I'm using cookies to pass the credentials between pages. But the function header() is giving me problems logging in and logging out. As you can see in the code below, I try to redirect the user to a page after setting or deleting the cookies. The scripts redirect okay, but the user never logs in and never logs out correctly. The scripts works correctly (logging in & logging out) only if I comment out the header() function. Here's my code for setting the cookie (login.php):
Delete File
I want to delete a file that is located on a server. The filename is in a Mysql database and now I have to put the line 'system("del c:apachehtdocsshopimg.gif");' somewhere in my code underneath. Any Idea how ? This line works already, but now the '.GIF' has to become a $file that equals the filename from the database...
Delete All Replicated Except One
I ran PHP codes that creating tables and inserting records to tables., But something happened, someone of them is inserted more than once. aa1345 | Ninsonoto aa1345 | Ninsonoto aa1348 | Ayumi Tohina aa1348 | Ayumi Tohina aa1348 | Ayumi Tohina There are thousands of records there. So I think i have to write a script that able to delete all the replicated except one.. e.g : Delete four of aa1348 records.
Delete New Lines
I would like to delete the new lines, I mean the, so Itried this: str_replace($row['facts_conten t'], " ", "") ; But the new lines are still there, how can I do?
Can't Delete From Table!
I'm not to familiar to php and sql. I have this assignment to read from database in a table and I HAVE TO be able to push a button causing one costumer to vanish. something to do with id = $id... can anyone help me... and help me fast! This is my code:
What Is The Best Way To Delete File ...?
I have script that allows a user to upload a txt file for processing, filtering, to save bandwidth,instead of user reuploading the file everytime he/she does a new process on the same file, i save the file to the server, and process from that file. What I want to be able to do is, when the user uploads a new file, or leaves the site, this temp file is automatically deleted (saves disk space).
Delete From Many Tables
I am trying to delete rows from a mySQL DB that consists of multiple tables. I am trying to use a function PHP Code:
Delete Records
I`m just trying to figure out the best method to delete my records and wondered if it was possible to do a DELETE statement to remove any records that don`t match. Here is my code so far: $Query="select blah its huge:-)"; $RESULT=mysql_query($Query); $my_rows=mysql_num_rows($RESULT); for ($a=0; $a<$my_rows; $a++){ mysql_data_seek($RESULT, $a); $Array = mysql_fetch_array($RESULT); printf("%s<BR>", $Array['Email']);} My Query returns Matched Records, what I would like to achieve is deletion of the records that didn`t match, would it be possible to do that under the printf statement. So delete all the records in the table that don`t match up to $Array['Email']??
SQL Insert And Delete?
Anyone know if there's a way to call a query but remove whatever you grabbed from the database, or would I have to do a query to retrieve what i needed, then follow it up with a delete on the same query results?
Delete An Object ?
I use OOP with PHP4 and i don't understand something. I have 2 classes VISIT & PLANNING like that: class clVISIT { var $when; var $where; //constructor function clVISIT($_when,$_where) { $this->when = $_when; $this->where = $_where; } } class clPLANNING { var $who; var $visit = array(); //constructor function ClPLANNING($_who) { $this->who = $_who; for ($i=0;$i<10;$i++) { $visit = new clVISIT("foo".$i , "foobar".$i ) ; } } } Ok, in the last constructor, we can see that i create new clVISIT object. My question is: how can i delete some of them in the same constructor ? is there a word like "new" but to delete ?
Delete Script
PHP and MySQL and I'm having some problems getting this script to work. I can't get this to work and I don't understand why. I don't get an error or anything, it almost seems like the page refreshes. I went to the phpmyadmin and the row is still in the database. The $_GET parts work perfectly in another script and the SQL statement works when I insert hard values in it. Any thoughts would be greatly appreciated. Thanks in advance. <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>"> <table> <tr><td colspan="2" align="center">Yes <?php input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php input_radiocheck('radio','yes_no', $defaults, 'no'); ?> </td></tr> <tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?> </td></tr> </table> <input type="hidden" name="_submit_check" value="1"/> </form> <?php function process_form() { // Access the global variable $db inside this function global $db; $isbn = $_GET['isbn']; $artist_name = $_GET['artist_name']; $album_title = $_GET['album_title']; if ($_POST['yes_no'] == 'yes') { $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name = '$artist_name' AND album_title = '$album_title'"; // Delete the record $db->query($delete_sql); print "The record was deleted"; } else { print "The record was not deleted"; } } ?>
Delete File();
I was wondering if php4 has a built in function that could delete a file. In my case I need my php to delete a picture. (jpg, gif) Does php4 have the ability to delete an exsiting file? Something like this?? delete_image("../images/somePic.jpg");
Delete Not Working
Can someone tell me why this delete isn't working: $strSQL = "DELETE FROM tblMine"; $rsEmpty = mysql_query($strSQL); I just can't get it work.
Delete File
Is there any way to use PHP to delete an external file?
DELETE Syntax
i have this code: $sql = "DELETE FROM $table_name WHERE subscribeid = $userid"; it works fine, but i also want to check some other variables when i delete. i want to use: subscribemail = $usermail subscribecode = $usercode i tried: $sql = "DELETE FROM $table_name WHERE subscribeid = $userid AND subscribemail = $usermail AND subscribecode = $usercode"; but it doesnt work. i looked in the manual but couldnt see what i was doing wrong, anyone got any ideas?
Delete From Database
I have code that does not delete from a database. The same code (cut an paste in the same file, but different function and having a different query) works. So, of course, I tested the query interactively. I echoed the query and did a cut and paste when interactively connect to the database. That one worked so it isn't the query since interactively it is seeing exactly the same thing as the code produces. Here is the code: function deleteCatalog($catalog) { $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'"; mssql_select_db($database_Login, $_SESSION['Login']); $result = mssql_query($query, $Login); ... } The $query echos: DELETE FROM CatalogNames WHERE sCatalogID='CMP' As an example of code that works (in the same file) function addToCatalog($cat_id, $cat_name) { $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " . "VALUES ('" . $cat_id . "', '" . $cat_name . "')"; mssql_select_db($database_Login, $_SESSION['Login']); $result = mssql_query($query, $_SESSION['Login']); ... } The second and third lines are identical (cut and pasted) as in other places in the same code. In fact, it is only in this file that I do all the database work. Every other function works. This is the only delete, however.
Delete From Array
let's say I have an array $letters(a,b,c,d,e,f) is there a function that will remove 'd' from the middle. I'm looking for something like array_delete($letters,'d');
Add/Delete Items
I have the following code, that displays a message whether a users shopping cart contains items or not. How do I add/delete items from the shopping cart, upon the appropriate product link being clicked? If a items is already in the cart, how do I display a message notifying the user? Code:
Delete Record
Im some having trouble with deleting a record, surely it isnt that hard, dont know what im doing wrong. this is the error i am gettin: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '` WHERE id=1' at line 1Here is my delete code:
Confirm Delete
The below code updates information in a table. I'm trying to add some type of validation to confirm that the user wants to continue with the update. The javascript is not doing what I want it to it makes the page white then I get a header error. Code:
Records Won't Delete
mysql_query("DELETE FROM guestbook WHERE id = '$recnum'"); It works fine on my local server but it doesn't delete records on the remote server. any ideas?
Trying To Delete Rows.
I am trying to use php to delete rows for a mysql database table, i am using the following code with $journeyIDToUse being a number that represents a automaticly incrementing primary key. $toDelete = "DELETE FROM journeyData WHERE journeyID='$journeyIDToUse'"; mysql_query($toDelete); This fails to delete the row. I have tried changing $journeyIDToUse to a number and that worked so i thought that the variable might be at fault but the following query works so that rules that out $searchString = "SELECT * FROM journeyData WHERE journeyID='$journeyIDToUse'"; $result = mysql_query($searchString); $row = mysql_fetch_array($result);
Delete Query
Here’s what I’m trying to do: - Output the last 60 results in my db - works - Delete a record – does not work Can anyone see why my delete query won’t work? It seems to have two problems: 1) It does not delete a record 2) The header re-direct says can’t modify header information Code:
Delete Old Timestamp
I want to delete all timstamp entried older than 2 days. This fails to delete do anything and there is no error. The field name is date and table name is logbook $sql="Delete from logbook where TIMESTAMPDIFF(DAY, 'date', NOW()) > 2 " ;
Delete Specific Row Out Of 3
Say i have three rows: row1 row2 row3 How do i make a mysql query to delete a specific row out of the 3 only? So say i wanted to delete row2 from the 3.. ?
Can't Delete Cookies
For some strange reason I can't seem to delete cookies. First it kept adding a new cookie a dot in front of the host when I set an already existing one with a negative expiry but now nothing happens at all. The code I'm using (with the domain changed) is: setcookie( "member_id", "4", time()-3600, "/", "www.mysite.net" ); The cookie remains unchanged and I have no idea why. The name, value, path, and host are correct but I still get nothing. I also tried: setcookie( "member_id", "", time()-3600); Again to no avail. It doesn't work on IE or FF. PHP version is 4.4.7 OS is Linux No error messages are displayed
Delete Folder FTP
I am trying to delete a folder and all of its contents (folders, files) through ftp. I am trying to modify a script for deleting it locally. I don't get any errors with this, but nothing happens. Can someone point me in the right direction? Code:
Delete From Table
I get this error not sure what's wrong? Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('mortalsombat@hotmail.com')' at line 3 Code:
|