PHP - How To Print A White Space To A Text File?
Hello, I have the following code writting IP,session, and date to a text file (it works) but I want to add a white space after the IP address.
fwrite($fp, $_SERVER['REMOTE_ADDR']. $_SESSION["sess_name"]. " $dateTime\r\n"); At the moment it prints like this 16.17.51.41SESSION_ID 2011/01/23 12:53:32 thanks in advance. Similar TutorialsI have a form on my website with a text area input field. I am looking for a php function that can strip the formating from the Text and take out line breaks and paragraphs so that when i retrieve the information from database i can change it from this _____________________________________ FANTASTIC BARGAINS ALL SPRING / SUMMMER 2010 ...... STOCK NOW REDUCED to this FANTASTIC BARGAINS ALL SPRING / SUMMMER 2010...... STOCK NOW REDUCED does anyone know what fucntion i could use for this? i have this so far but it doesnt seem to be working $descr = ''; if(strlen($row['description']) > DESCR_LIMIT) { $descr = (substr($row['description'], 0, DESCR_LIMIT).'...'); } else { $descr = $row['description']; } $descr = preg_replace("/(\r\n)+/", " ", $descr); $descr = preg_replace("/ +/", " ", $descr); $status .= $descr; I have tried to look google, but was unable to find anything. and the search daemon is giving me errors on this site. So, when I am calling lines from a text file, I am getting a problem. to explain, I will use a # to show were this "white space" is I am getting This is the text file Code: [Select] url.com url2.com url3.com when PHP reads the file, and I output it into PHP its reading it like this Code: [Select] url1.com# url2.com# url3.com url1.com and url2.com both are getting this "white space" at the end of them, and the last entry does not. I have tried to use str_replace(" ","",$line) and str_replace("\r","",$line) but nothing. can anyone advise me as to what character this is that is being outputed. my code I'm using $f = fopen ("list.txt", "r"); while ($line= fgets ($f)) { if($url == $line){echo $line;} } fclose ($f); I'm familiar with 'trim' and even tried the following: $datanew = str_replace(array("\n", "\r", "\t", " ", "\o", "\xOB"), '', $data); but for the life of me I can't remove any white space within the source code which is messing everything else up. This is what I need: What people see.... Code: [Select] word1 word2 word3 The source... Code: [Select] word1 word2 word3 This is the current situation What people see... Code: [Select] word1 word2 word3 The source... Code: [Select] word1 word2 word3 For whatever reason, if I can strip the whitespace from the source code then I can use the content accordingly. How would do you strip the white space? Does this even make sense? Anyone know how I can print a file (specifically a PDF) that is stored on the server to the clients computer with a button? I don't want them to be able to view it, just print it. I've done some research and understand that there is no way to print directly without popping up the Windows Print dialog. And that is fine. I just want them to print this file, but not no where it is or be able to type in a URL to access it. Thanks Mike Hi i have this edit form that allows user to mofy data but the problems on the text box is that it deletes the rest of the data after the space from the first word i tried to increase the size of the varChars on mysql but did no work why it happens how can i stop from happening?? this the form input <input type="text" name="name" id="name" class='text_box' value="<?php echo $_GET['name'];?>"/> Hi im having trouble with uploading images with spaces in as they dont show up in the browser. Here is the code: Code: [Select] $image = addslashes($_FILES['image']['name']); $target = "images/"; $target = $target . basename( $_FILES['image']['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { Any help would be appreciated. Hello guys and gals, I am pretty green to PHP! I have an empty array that that I am trying to put images into. The thing is I have a certain file name in the folder, I want to exclude that file. This is what I have tried, any advice would be appreciated! Code: [Select] $thumbImg[] = array(); foreach (glob($DImg) as $PImg) { if (!is_file("thumbnail.jpg")) { $thumbImg[] = "<img src=\"pathtoimage\">"; } } Later on the page I am printing it out with this. It is still including the thumbnail.jpg image. Thank you in advance!! Code: [Select] for ($i=0; $i<count($thumbImg); $i++) print $thumbImg[$i]; Hello, hi, whats the best way to print labels. I have already tried the script from fpdf.de but i can not get my dot matrix printer (dot matrix is needed for this purpose) the correct layout. Its continuous paper, with size 110 height x 62mm width (for each label). I am not able to select a self-adjustable paper-size. so i hope to solve this with PHP / PDF if possible. anyone have experience with this? cheerz!! is there a way to print the file as it appears. I want to print the HTML and PHP within a file rather than just the output. Example: File contains: <?php echo "Hello World"; ?> i would like to echo: <?php echo "Hello World"; ?> instead of just hello world which is what i get with file_get_contents() What im trying to do is create a file with the name "triangular_10.txt" where the number in the file name is the number the user entered. From there I want the text file to have the triangular series of numbers. So if the user enters 10, it'll display the first 10 numbers of the triangular series. So far the file name change is working. The algorithm is here that I used for PHP:http://www.codecodex.com/wiki/Calculate_a_triangle_number eg . user enters 10. Result in txt file is first 10 numbers in the triangular series = [1, 3, 6, 10, 15, 21, 28, 36, 45] This is what I have so far but Im not having any luck! At the moment its only writing the number I entered on to the txt file and nothing else! Any ideas? $number = $_POST['number-entered']; foreach ( range(1, 1000) as $i ) { $triangle_numbers[] = $i * ( $i + 1 ) / 2; } //make a file $contents = fopen('gs://a1-task22020.appspot.com/triangular_' .$number. ".txt", "w"); fwrite($contents, $number); //open the file $contents = fopen('gs://a1-task22020.appspot.com/' . $contents, 'w'); // re-open the document if you put something in it fwrite($contents, $number); fclose($contents); } }
while($row = mysql_fetch_row($query)) { echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } Currently I have this code. I would like to make it print certain text, let's say... 'car', if the value of table's column 'automobiles' is equal to 0. Otherwise - print the real value. I've tried if statement and $one = $two... But that apparently didn't worked. Thanks. Hi guys, does anybody know of any good libraries to handle and validate file uploading including Zipped folders. Also I was needing some tips, so my website developers can come and upload zipped folders, files etc. but eventually would'nt this start taking up a lot of space especially the zipped folders?
Hello, I am attempting to create a script where a user puts a text string into a form and clicking on submit. Then it adds that text string to a mysql database and gives the user a link back to it. Something like mysite.com/key.php?id=4 and when going to that link it will display the text string from the database but printed in an image. I wrote something up but I cannot get it to work. I may be a little in over my head. Any help is appreciated.
The way I coded this all to work is the user inputs the information into index.php which givekey.php inserts that into the database. I have not yet figure out how to do this in one single step. After that I wanted it to navigate directly to key.php which would display the key and the link to that page with the ?key=XX attribute. getkey.php <?php require_once 'dbinfo.php'; // database connection $id = $_GET['id']; // do some validation here to ensure id is safe $link = mysql_connect($servername, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT ukey FROM keycode WHERE id=$id"; $result = mysql_query("$sql"); $row = mysql_fetch_assoc($result); mysql_close($link); header("Content-type: image/png"); echo $row['ukey']; ?> key.php <html> <head> <title>Your Key Is Ready</title> </head> <body> <img src="getkey.php?id=1" width="175" height="200" /> </body> </html>index.php <html> <head> <title></title> </head> <body> <section id="mid_section"> <div id="boxes"> <h1> Testing input key </h1> <br/> <form id="myform" action="givekey.php" method="post"> Key:<br /> <input type="text" value="ukey"> Source:<br /> <input type="radio" value="hb">HB<br /> <input type="radio" value="ig">IG<br /> <input type="radio" value="other">Other<br /> <button id="sub">Submit</button> </form> </body> </html>givekey.php <?php include_once('dbinfo.php'); $conn = mysql_connect($servername, $username, $password); $db= mysql_select_db($database); $ukey =$_POST['ukey']; $hb =$_POST['hb']; $ig =$_POST['ig']; $other =$_POST['other']; if(mysql_query("INSERT INTO `keycode`(`ukey`) VALUES ([$ukey]); INSERT INTO `source`(`hb`,`ig`,`other`) VALUES ([$hb],[$ig],[$other]);")) ?> Edited by chrisb302, 13 November 2014 - 12:18 AM. I have some problem when I want to echo out a text which is retrieve from my database and place it inside a text box but it stops showing when there's a space. If I echo it out outside of the textbox, then there's no problem. May I know how to resolve this problem. Thanks Hello, I am having a problem with a link text when ever there is a text that has multiple words. (e.g. 2 Cor prints out with the white space but when I click on the text the url is printed without the text as 2Cor and so it doesn't find a match) here is my code: Code: [Select] <?php if($_GET['book'] == ''){ $books = $wpdb->get_results(" SELECT book_name FROM {$wpdb->prefix}sb_books_sermons LEFT JOIN {$wpdb->prefix}sb_books ON {$wpdb->prefix}sb_books_sermons.book_name = name GROUP BY book_name ORDER BY {$wpdb->prefix}sb_books.id ASC "); foreach($books as $book){ echo '<li><div class="droidlist"><a href="bible/?book='.htmlentities($book->book_name).'">'.$book->book_name.'</a></div></li>'."\n\t"; } } 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 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 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. I have a table with postcodes in it. At some point some of the codes will be entered with spaces (LA12 5TH) and some without (LA17HU) what i need is a function to check if there is a space, if not - count back 3 characters from the end of the string and insert a space. I don't know which string function to use - looked at pad but that seems to be for either end of string and not the middle - any ideas? |