PHP - How Can I Amend To A Text File So That The Text Is Added Before A Hyperlink?
Hi,
I am writing several scripts and some are used to amend extra information to a text file. However, I added a hyperlink to the text file so that the user can go back to a page where they can add extra information. However, since I have done this every time I amend more text to the text file, the extra text appears below the hyperlink rather than above it, and I was wondering if there was a way around this. My amend code is as follows: Code: [Select] <html> <head> <title>Amend File</title> <link rel="stylesheet" type="text/css" a href="rcm/stylesheet.css"> </head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="<p>Updated Information: " .$_POST['append']. "</p><br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" size="40" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> </body></html> And my text file is as follows: Code: [Select] <h1>Accident Report</h1> <p>First Name: Andrew Last Name: Denman Age: 18 Complete Weeks Since Accident: 2<br> <a href="amendfile2.php">Amend to this file</a> Any help would be appreciated Similar TutorialsHello I've some text and I want remove hyperlink that in text. for example this code : Code: [Select] <p align="left"><img src="http://www.ebookz.ir/static/images/book/PhotoshopElements9:TheMissingManual.jpg" width="180" height="220" align="right"></p></br><b>Paperback:</b> 640 pages<br /><b>Publisher:</b> <a href="http://www.ebooks.com/tags/Pogue+Press/" >Pogue Press</a>; 1 edition (September 29, 2010)<br /><b>Language:</b> English<br /><b>ISBN-10:</b> 1449389678<br /><b>ISBN-13:</b> 978-1449389673<br /><br />Elements 9 offers much of Photoshops power without the huge price tag. Its an ideal tool for most image-editing buffs -- including scrapbookers, photographers, and aspiring graphic artists. But Elements still doesnt come with a decent manual. This bestselling book will help you get the most out of the program, from the basics to advanced tips for both Windows and Mac. <br />Quickly learn your way around. Customize Elements to suit your working style. <br />Get to work right away. Import, organize, and make quick image fixes with ease. <br />Retouch any image. Learn how to repair and restore your old and damaged photos. <br />Add some pizzazz. Give images more zip with dozens of filters, frames, and special effects. <br />Find your creative flair. Create scrapbooks, greeting cards, photo books, and more. <br />Use advanced techniques. Work with layers, blend modes, and other tools. <br />Try out your new skills. Download practice images and try new tricks as you learn.</div></div> I want remove this hyperlink <a href="http://www.ebooks.com/tags/Pogue+Press/" >Pogue Press</a> can anyone help me? Hi guys, I have added a column in a database, I know how to read the information from the database but I don't know how to check with the column name called "public" whether if the cell has text called enabled or disabled, then add the href link in enabled or disabled text in my php. I need it to allow the clients to control on their own account. Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, public FROM members WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?id='.$row['id'].'">Delete</a> </td> | Enabled | Disabled'; } } } ?> What I am trying to achieve is to check the column name called "public" whether if it has text that stored in the database (it could be enabled or disabled) then add the hyperlink in that text of enabled or disabled in the php page so it would allow the user to click one of the link to allow the hyperlink to switch over from enabled to disabled. E.G: A user is going to click the enabled text with the hyperlink to change the text in the database from enabled to disabled and remove the hyperlink in the php page from enabled to add the hyperlink in the disabled text. Do anyone know how to do this? Any advice would be much appreciated. Thanks in advance. I currently am working on a project where I code a "simple" telephone directory. There are three main tasks that it needs to do: 1. Directory.php(index page) has a "First Name" and "Last Name" field and a search button. When a name is searched from the directory.txt file, it displays First Name, Last Name, Address, City, State, Zip and phone in findinfo.php in designated text boxes...first name, last name, etc. 2. From the findinfo.php, like previously stated, the users information is listed in the appropriate text boxes. From there, there is an update button that will overwrite the user's information to directory.txt if that button is selected. It will then say the write was sucessful. 3. (completed this step) From the index page, there is a link that will take you to addnew.php where you enter First Name, Last Name, Address, City, State, Zip and phone in a web form and write it to directory.txt. This is the php code for the third step: <?php $newentryfile = fopen("directory.txt", "a+"); $firstname = $_POST['fname']; $lastname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $newentry = "$firstname $lastname\n\r $address\n\r $city, $state $zip\n\r $phone\n\r"; if (flock($newentryfile, LOCK_EX)) { if (fwrite($newentryfile, $newentry) > 0) echo "<p>" . stripslashes($firstname) . " " . stripslashes($lastname) . " has been added to the directory.</p>"; else echo "<p>Registration error!</p>"; flock($newentryfile, LOCK_UN); } else echo "<p>Cannot write to the file. Please try again later</p>"; fclose($newentryfile); if(empty($firstname) || empty($lastname) || empty($address) || empty($city) || empty ($state) || empty($zip) || empty($phone)) { echo "<p>Please go back and fill out all fields.</p>"; } ?> So to sum it all up, what would be my best approach? I am totally stumped and not sure which function to use. Should I work my way from step 1 to step 2? I see it as when I do the search for the name from directory.php, it takes me to findinfo.php, listing the users information in the text boxes. From there, if I needed to, having the user's information already listed I could hit the update button to overwrite the new information to directory.txt. Doing the update when then tell me that the write was successful. I have literally been scouring the internet for hours. What would be the best function to do this? I hope I was clear enough. Please help me out and thank you for your time. Ok i have been working on this for a day+ now. here is my delema simple .ini text file. when a user makes a change (via html form) it makes the correct adjustments. problem is the newline issue 1. if i put a "\n" at the end (when using fputs) works great, except everytime they edit the file it keeps adding a new line (i.e. 10 edits there are now 10 blank lines!!!!) 2. if i leave off the "\n" it appends the next "fgets" to that lilne making a mess Code: [Select] ##-- Loop thruoght the ORIGINAL file while( ! feof($old)) { ##-- Get a line of text $aline = fgets($old); ##-- We only need to check for "=" if(strpos($aline,"=") > 0 ) { ##-- Write NEW data to tmp file fputs($tmp,$info[$i]." = ".$rslt[$i]."\n"); $i++; } ##-- No Match else { fputs($tmp,$aline."\n"); }//Checking for match }//while eof(old) what in the world is making this such a big deal. i dont remember having this issue in the past I tried opening with w+, and just w on the temp file a typical text line would be some fieldname = some value the scipt cycles through the file ignoring comments that are "#" ps the tmp file will overwrite the origianl once complete all i really want to know is WHY i cant get the newline to work, and what is the suggested fix EDIT: i just tried PHP_EOL and it still appends another newline I got two values from a form in a page by POST method. Now I want to add this values to a text file. The code of form1.htm is like this: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form action="write1.php" method="post"> <fieldset> <legend>Log In...</legend> <input type="text" name="uname" /><br> <input type="text" name="pass" /><br><br> <input type="submit" name="button" value="Log In" /> </fieldset> </form> </body> </html> And the code of write1.php is like this: <?php function arr_func() { $name = $_POST['uname']; $pass = $_POST['pass']; //trying to catch values in an array $arr[] = array("name"=>"$name", "pass"=>"$pass"); foreach ($arr as $val_arr) { foreach ($val_arr as $key=>$val) { echo "$key - $val<br>"; } echo '<br>'; } } $arr1 = arr_func(); //values are printed, no problem echo $arr1; //trying to change the array into string, is it wrong approach? $var1 = strval($arr1); // set file to write $file = 'student/dump.txt'; // open file $fh = fopen($file, 'w') or die('Could not open file!'); // write that variable into file fwrite($fh, "$var1\n") or die('Could not write to file'); // close file fclose($fh); ?> After log in in form1 I get two values of $name and $pass in write1.php but no values being added to the file mentioned in the path. How would I open a text file from another server and echo it. http://mysite.com/news/feed.txt Hello everyone, This is my first post and I need a little help. My knowledge of php is limited, so this question may look simple. English isn't my mother tongue, which you have probably noticed already. So, my problem: I 've made a a phpscript that adds text to a txt-file, that works perfect, but I also need something to delete some parts of the file. part of my html-code: Code: [Select] <form method="POST" action="verwijderscript.php"> <table class="noborder"> <tr><td class="noborder"> <input type="text" id="verwijdertitel" name="verwijdertitel" size="40"> <input type="submit" name="s1" value="Verwijder Bericht" /> </td></tr> </table> </form> part of my txt-file: Code: [Select] <div id="Testtitel"> <span class="subtitel">Testtitel</span> <span class="rechts">Gepost op 15/03/2011</span> <br> <img class="nieuws" src="image.gif"><br> texttexttexttexttext<br> texttexttext<br> text <div class="streep"></div> </div id="Testtitel"> <div id="Testtitel2"> <span class="subtitel">Testtitel2</span> <span class="rechts">Gepost op 15/03/2011</span> <br> <img class="nieuws" src="image2.gif"><br> texttexttexttexttext<br> texttexttext<br> text <div class="streep"></div> </div id="Testtitel2"> part of my php-code: Code: [Select] <?php $titel = $_POST['verwijdertitel']; $oud = file_get_contents("data.txt"); $data = fopen("data.txt", "w+"); $nieuw = str_replace("id=\""$titel, "id=\"hidden", $oud); fwrite($data, "$nieuw"); fclose($data); header("refresh:0;url=http://www.test.com"); ?> css: Code: [Select] #hidden{display:none;} Problem: parse error line 6 of php-file And I don't think this works if the error is solved. I don't have a MySQL database, that's why I use a txt files. What I try to do is to hide the div, it would be better to delete it, but than I need to work with regex, I guess 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 . Hello, I am trying to read data from a text file but also adding up the 4th column for example 'name' 'more' '1.00' 'evenmore' so were the 1.00 is I want to add it up is there anyway ? Ok, I have a log file that is written to. I only want the text file to have the last fifty lines (\n) delimited So, how do I make it delete the excess from the TOP of the file? So if it had 60 lines, I would want it to only have lines 10-60 to net 50 total. Thanks. Hello, I had simple php website in one folder, no database in the website. I need a method for text search in the web directory... Any help? Thanks $tracking_file_location = "../dispatch-manager/logs/tracking_file.txt"; $tracking_file = fopen("$tracking_file_location", "r") or die("Unable to open file!"); $tracking_file_size = filesize("$tracking_file_location"); $tracking_file_text = fread($tracking_file,$tracking_file_size); fclose($tracking_file); I am trying to add a txt file to a mysql database. Is there any one that can help? Here are the details TEST.TXT contains the following A001200910019999999900000200000000000000000000000 00000000000000000000000000 A002200910019999999900000610000000000000000000000 00000000000000000000000000 A003200910019999999900000687500000000000000000000 00000000000000000000000000 A004200910019999999900000335000000000000000000000 00000000000000000000000000 A005200910019999999900000626500000000000000000000 00000000000000000000000000 A006200704019999999900000423500000000000000000000 00000000000000000000000000 A007200910019999999900000323500000000000000000000 00000000000000000000000000 A008200704019999999900000102500000000000000000000 00000000000000000000000000 And so on up to 200 rows long I need to split each row the same way and add them to a table I will use the first row as an example Character 1 to 4 (A001) entered into a field called name Character 5 to 12 (20091001) entered into a field called efdate Character 13 to 20 (99999999) entered into a field called exdate Character 21 to 31 (00000200000) entered into a field called prfee Character 32 to 42 (00000000000) entered into a field called assfee Character 43 to 53(00000000000) entered into a field called spfee Character 54 to 64 (00000000000) entered into a field called anfee Character 65 to 75 (00000000000) entered into a field called nanfee Thanks in advance for the help Hey, Currently i have a chat room which calls my database quite frequently... so im thinking i can lower the heavy load from my server by taking it off MYSQL methods and using PHP read/write/delete methods of a text file. Now i have two issues with this... first one is: Code: [Select] <?php $myFile = "chatlist.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $Message.'<br/>'; fwrite($fh, $stringData); fclose($fh); ?> This writes the most recent line, how ever the next line that gets sent overwrites so theres only ever one line in the txt file =/ Secondly how on earth do you delete a specific line from the file efficiently ? Say for example a line which broke the rules some how like spam was posted etc. Hope you get shed light on this. Thanks ok I have a text file that has ids listed each on a new line how can I go about assigning each id to a variable so like 12312412 23432443 34654366 56456345 the variable $ids = all of the ids above one at a time in an array so like $ids[] = 12312412; $ids[] = 23432443; $ids[] = 34654366; $ids[] = 56456345; i have a log file which gets new data time by time. is there any way i can read only new added entries (block) in the file? instead of start reading file from start to the end of file. this file size will be in GBs soon. Thanks. currently i am using file() to read the file. following is the example of new added block in file.
----SMS_START----
recv_time:2014-10-09 18:32:39 Span: 1 From-Number: +1347XXXXXXX Timestamp: 14/10/09 18:32:16 96 Type: PDU SMS-SMSC-Number: +12404492163 Content: Thanks, ----SMS_END---- 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 there, I need to know how to code a php file, to jump to a specific point in a text file. I haven't a clue what you would use and need the file to do very simply, or so it seems to find the line starting with: "!CLIENTS", then go to the next line and take the information from thereon out UNTIL it reaches a blank line, where it would dis-regard it and stop. Is that possible? Hi, Everyone! I have an issue and I'm not even sure if it can be done with PHP, but even this info would help me (to stop looking for an answer). I need to populate a (MySQL) database with stuff which is now written in a (HTML formatted) file. Here are my options: 1. Copy/paste each single field via PHPMyAdmin . 2. Write a little script to extract the necessary parts of text from these files to create a CSV-like content which I would then easily INSERT into the db. Example The files look like this: Code: [Select] <!-- SEPARATOR (same throughout the file(s) --> <tr><td> <div style="something"><img src="img/what_i_need_to_extract_1.png"></div> </td><td> <div style="something else"><b>What I need to extract 2</b></div> <div style="something else">What I need to extract 3</div> </td></tr> <!-- SEPARATOR (same throughout the file(s) --> etc ... and it goes like... 100 times in each file in the same standard pattern with the "What I need to extract" parts being completely different each time. Since it's possible to tell when each part required for extraction begins and ends, I would expect the script to look for these key-points (according to the example, it would be: img/ to "></d then "><b> to </b>< and else"> to </div>) and return a result like this (acc. to the example): ('what_i_need_to_extract_1.png', 'What I need to extract 2', 'What I need to extract 3'), (and so on...). Is it possible? Is there a function/option/way to look for a start/end-point like this and fetch the part between these two set points? If so - how? Any help would be appreciated, I'm not expecting a full code, obviously, just a point to the right direction or where to look at would be nice. Thanks in advance. |