PHP - Better Way To Remove First 3 Lines?
My current code (which works):
Code: [Select] <?php $body = explode("\n", $body); $body = array_slice($body, 3); $body = implode("\n", $body); ?> Is there a better way of doing this, so I dont have to explode and implode an array just to accomplish this? Similar TutorialsDear all, I want to remove all lines less than 3 words longs so I can stuff the rest into a db. Can somebody help me? Thank you in advance Extremely new here and to PHP and I have exhausted my newbie resources and my brain on this one. Concept: Cron Job to INSERT 5 lines per hour (Not the whole list at once) Script to read a pipe delimited text file (about 5k Lines) Open File Get last (bottom) 5 lines of file, ignore the rest Insert those 5 lines into my database Open File, Remove last (bottom) 5 lines I am able to do parts 1-3 but not part 4 (removing last 5 lines) Please help me! Code: [Select] $data = array_slice(file('data.txt'), -5); foreach($data as $value) { $fields=explode("|",$value); $num=count($fields); for ($n=0;$n<$num;$n++) { $null=""; print ($n==0) ? "Importing Video...<BR>" : $null; } // Insert into tmpvideos table here include("includes/config.php"); $last_id_result = @mysql_query( @"SELECT ext_id FROM tmpvideos ORDER BY ext_id+0 DESC, id DESC" ); if ( 0 < @mysql_num_rows( $last_id_result ) ) { $last_id = @mysql_result( $last_id_result, 0, "ext_id" ) + 1; } else { $last_id = "1"; } copy($fields[3], "thumbs/ex_".$last_id.".jpg" ); $fields[3] = "thumbs/ex_".$last_id.".jpg"; set_time_limit(0); mysql_query("INSERT into tmpvideos (id, ext_id, title, description, duration, category, date_added, thumb, video, views, rating, votes, status) VALUES ('','".$last_id."','$fields[0]','$fields[1]','$fields[5]','$fields[6]',NOW(),'$fields[3]','$fields[2]','','','','1')"); } I understand the 'concept' but am unable to grasp the code! I have tried many snippets and really need help. This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=349934.0 is this possible? First problem fixed. My second problem is if the result is 0X.XX,0 or 0X.XX,1 I would like to remove the first 0 The X.XX are numbers, but the 0 is not always there. Can anyone help please Thanks Good morning, I passed a bunch of HTML tags over a function that delete then, keeping just the text between. The problem is, after that all the tags were replaced by line breaks. Something like this before the function: <tr> <td> Text </tr> </td> After the function the 4 tags were correctly removed but instead i receive just the string "Text" I receive 2 line breaks, the "Text" and other 2 line breaks, like this: Text In HTML code this line breaks has no tags like <br> or <p> it's just blanck lines. I need to get just the text, how can I get rid of then? I tried this and also didn't work. $text = str_replace("/n", "", $text ); Thanks Danilo Jr. hey guys i have to following code <?php include("users/index.php"); ?> <?php $LOGIN_INFORMATION = array( $user_login_username => $user_login_password, ); ?> the script connects to the database and fetches the data the problem im having is the table has 3 tables "ID" - "user_login_username" - "user_login_password" in those tables are 2 entries "1" - "test" - "user" "2" - "test1" - "user1" now on the login screen when i enter the username and password "test1" and "user1" it logs me in fine and works how i want it to but when i enter "test" and "user" it doesnt work if i add another entry so the table shows "1" - "test" - "user" "2" - "test1" - "user1" "3" - "test2" - "user2" and i try the to login again with "test" and "user" it fails and so does "test1" and "user1" but "test2" and "user2" works the script is only fetching the last entry from the DB is there anyway to login with any user in the DB?? if this dont make sense or you need more info please ask Thanks Can you please tell me what each of these lines of code means?
$allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); $length = 20; $newfilename = $_SESSION['user_id'].$_FILES["file"]["name"]; $thumbnail = $newfilename . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail); $sql = "INSERT INTO videos ( filename ) VALUES( $thumbnail )"; mysql_query($sql); $file_location = '<a href="http://www.--.com/upload/' . $thumbnail . '">' . $thumbnail . '</a>'; $description = $description . " \n " . $newfilename; Hello, I'm creating a program that analyzes information that is exported by another program. That program exports it in this way: Value1 Value2 Value3 Value4 Value1 Value2... In order to insert them in the database, I first have to know how many lines are inserted. They get send through HTML post. I already tried: $lines = explode("\n", $string); $number_lines = count($lines); But this always results in 1. How do I fix this? Regards, Chris Hi All, Im new to this forum but think its going to be a regular location for me for quite a while. Im very very new to php and the guy that was doing code for me is not responding to emails, so i thought id have a go myself...lol at the moment im going through the trial and error phase while learning. I have edited some of the code he has put on the site to create a new look. the original page: http://www.ridersguide.co.uk/county_accommodation.php?county=4; the one im trying:http://www.ridersguide.co.uk/county_accommodation2.php?county=4; The new bit is to add a preview of the text for the page. echo $row[ad_text]; the code above brings up all the text but i only want to show the first 4 or 5 lines. Is this possible in php? Any help appreciated Neil Hi, I am trying to parse a html page, but i get a lot of empty spaces, please any idea how can i remove spaces, here is my text: Code: [Select] this goes here one line here some other line here see there is a lot of space between text, thanks for any help Hi all, Hopefully this will be a very easy question for one of you! Basically, I've created a little invoice script, and I need some help with the invoice data (i.e the item info, qty and the price). My question is how do i deal with the data from multiple rows containing 3 text fields each (item, qty and price). I've been playing with a foreach loop, which I can make echo info in the item field for each row. How do I incorporate the other fields (the qty and price)? Can I build an array to hold it all? Thanks for any help! Jim I have a Description field that gets sent to my Payment Gateway which can be put in an e-mail to my customer after a successful purchase. Is it possible to have multiple lines and line-breaks in one Array Value?? For example... Code: [Select] $post_values = array( "x_description" => "Fuzzy Sweater Girls Medium Long-Sleeve $75", Debbie l have a video site, and each title is generated dynamically on a <li>. The problem is some titles are longer than others and spill on to the next <li> throwing my site all off. What i need to do is designate 2 lines for the titles just in case the title is too long. Code: [Select] <ul> <li><?php echo $title; ?></li> <li>///continue $title or add blank line so it doesn't throw everything off</li> </ul> Thanks ahead of time, I have been working this all week end but get lost.... a. I want to insert all the lines from file1.txt into file2.txt . b. I want the all lines in file1.txt to be inserted in file2.txt starting at "<image>" tag label in file2.txt. c. I would like to overwrite all lines that start with the "<image>" tag in file2.txt with the insert (text in file1.txt contains <image> tag also). file2.txt has lines above and below the insert point <image>. The insert text (file1.txt) could be as many as twenty lines (records) all/each beginning with the<image>tag. Here is what I have done so far. <? $key = '<image>'; //a text tag in $file1 and $file2 //copy file $file = "file1.txt"; $file2= 'file2.txt"; $newfile = "filetemp.txt"; copy($file, $newfile) or exit("could not copy $file"); //load file array $fc = fopen ($file, "r"); while (!feof ($fc)) { $buffer = fgets($fc, 4096); $lines[] = $buffer; } fclose ($fc); //open same file and use "w" to clear file ,not sure this is needed $f=fopen($newfile,"w") or die("$file did not open"); /* uncomment to debug print_r($lines); print "<br>\n"; */ //loop through array 'foreach foreach($lines as $line) { fwrite($f,$line); //rewrite $line in file if (strstr($line,$key)){ //find $key in each line fwrite($f,$newline."\n"); } //rewrite $line in file } fclose($f); copy($newfile, $file2) or exit("could not copy $newfile"); ?> Again thanks ahead of time, I just keep losing the flow, old I guess. Tom I have a task that seems to be complex.
Short Description: currently users of the application I am hired to develop have two steps to do when using the app:
1. Select a Product Line (A, B, C, D)
2. Select input parameters for that product line - all product lines have simlar "Main" input parameters, but also each line has its own special features that can be selected.
3. Selections for that product line are shown - the result is a long table or options for that particular product line. Things like price, discounts, product specifications, etc.
What the users want now is this:
1. Select input parameters (not sure how to handle individual product lines special parameters yet)
2. Selections for all product lines are shown
The code base is legacy code, with code thrown around everywhere. One idea me and my coworkers have been considering is a complete rewrite, since it will help us with writing tighter code, and do what the customer wants. But that will also take time, and there is no spec. The spec is in the code mess.
Another one is I am considering now is a "merge". Somehow merge the product lines, since we have the separate product modules (A, B, C, D), there must be a way to consider maybe extending one to include the others, or somehow get me to the end result -- allow users to see selections for all product lines.
Do you have any experience, any suggestions on how to do this? I know this needs details, and details are in my code that you don't see, and most likely won't have the time to read and understand anyway.
But I am looking for any ideas or encouragement though that may help. And my question is -- is there any kind of procedure or technique or something to deal with the problem I am facing -- merging several separate yet similar modules into one single merged module. How do I approach this, what are some things that could help, etc. That's what I'm looking for.
Hello!
I need small help. Need php script for changinh milti lines in myslq database. In database are fiekds: date, ip, status
1. 2014-09-01, 123, 0
2. 2014-09-01, 444, 0
3. 2014-09-01, 123, 0
4. 2014-08-31, 888, 0
5. 2014-09-01, 444, 0
6. 2014-09-01, 123, 0
Now script must search ip and date.
1. record is OK,
2. record is OK,
3. record NOT OK, because date and ip are in first record, must change status to 1
4. record is OK,
5. record NOT OK, because date and ip are in second record, must change status to 1
6. record NOT OK, because date and ip are in 1 and 3 record, must change status to 1
While using the PHP strip_tags() function,I used the optional second parameter to specify tags which should not be stripped.
However with these allowable_tags, I realised strip-tags is not safe. for example with a string such as this ($str= "<p onmouseover=\"evilscript url\"> Hi, this is an interesting link. </p>") I was able to load a page containing a script injected into it, that script was able to rip off my session cookie ID!!!. To further strengthen data sanitization using the strip_tags() function, I have come up with this function below which does the following: allows the use of the following html tags: <h1><h2><h3><h4><h5><h6><a><br><table><ul><ol><li><p><img> remove classes, ids from html tags remove font-style, font-size, color,font-family,line-height from style tags in the text; remove javascript attributes within a tag remove empty style tags function CleanUp($InputString) { $RemoveAttrib = "'\\s(class|id|javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup)=\"(.*?)\"'i"; //remove classes, ids and disallow these attributes/prefix within a tag; $InputString = strip_tags($InputString, '<h1><h2><h3><h4><h5><h6><a><br><table><ul><ol><li><p><img>'); $InputString = preg_replace($RemoveAttrib, '', $InputString); $RemoveAttrib = "/(font\-size|color|font\-family|line\-height):\\s". "(\\d+(\\x2E\\d+\\w+|\\W)|\\w+)(;|)(\\s|)/i"; //remove font-style, font-size, color,font-family,line-height from style tags in the text; //$InputString = stripslashes($tagSource); $InputString = preg_replace($RemoveAttrib, '', $InputString); $InputString = str_replace(" style=\"\"", '', $InputString); //remove empty style tags, after the preg_replace above (style=""); return $InputString; }This worked well for single line text, but if I had hard returns in the text the function could not find the other tags to remove, and therefore failed. See below. <p id= "mike" style="line-height: 150%; class="lead">The function did not strip off the paragragh ID attribute.</p>Or <p id ="mike" style="line-height: 150%; class="lead">The function did not strip off the paragragh ID attribute.</p>I tried marching New lines as shown below but it did not work: $RemoveAttrib = "'\\s(class|id|javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup)(\r\n)*?=\"(\r\n)*?(.*?)\"'i";I need help to fix this. Thanks. HI I am very confused right now guys. I have no idea how to evaluate my upload script. This adds CSV lines into my phpmyadmin table and it works fine, but i want to make it more user friendly so users could simply `save as` an XLS file into a CSV file without making any adjustments. And so the program would do most of the work from there. So if my CSv file looks like this: , ,, ,,,,, some word, random, ,,,, #Batch 312-313 312,John Smith, New Jersey,, //line 1 313, Ana White, California,, //line 2 #Batch 314-315 314, Greg Long, Mexico //line 3 315, Jane Snow, Texas,, //line 4 Prepared by:, Jack Brown, CPA I need help on how to add only the four lines into the fields: `number`, `name`, `address` How do i disregard any other things in the CSV except for words that should be on my database? Thank you for your time, and have a nice day. I have a form that is processed using PHP (post method) and there is a textarea people will enter text into. After processing, the text is displayed to the user. However, if the user did a Carriage Return (i.e. hit Enter) when they originally entered the text, that text does NOT show on a new line when displayed later. For example, if they type this into the text area... "Hello there (they hit Enter here) How are you (they hit Enter here) Good I hope" It will display like this, all on one line: "Hello there How are you Good I hope" In other words, it doesn't seem to remember that Enter was hit. Is there some way to "preserve" the fact that someone hit the "Enter" key, so that when text is displayed later, it will show the text on a new line if the user in fact hit "Enter" when originally typing it. I am probably not using the right terms in the right spots (i.e. newline, carriage return, enter, etc) but I think you get the picture Let me know if anyone knows how to do this. Thanks! |