Jump to content

Nyla

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by Nyla

  1. Thank you Jacques, I'm like a "trial-and-error" parser hahaha -- I try and try and try. But your post is very clear and articulate, and I probably won't have to bother you again for a long time. I appreciate your help, and appreciate you helping me solve the problem at hand. Thank you again, and happy new year!
  2. Hansford, that's cool! But how come your method works? I believe " \s " means space, right? Well does preg_replace treat "new lines" (e.g. "traversing lines" as I referred to?) as spaces? If so, why doesn't .* or .*? work? Doesn't that mean "everything up to" ??? I'm so dumb. I'll learn fast, though, whatever you tell me.
  3. Well Mister Mister, since I don't like being bossed around, I'm going to read, learn, and MEMORIZE the entire PHP manual cover-to-cover, EXCEPT the part about the "s modifier." So there...I'll teach YOU a lesson! LOL THANK YOU!!!
  4. How come preg_replace won't traverse multiple lines? <?php $str = ' one two three four '; echo preg_replace("/two.*three/",'xxx',$str); ?> The result should be: one xxx four ...but it looks like preg_replace doesn't go from one line to the next?
  5. OMG OMG THAT'S IT!!!! FINALLY!!!! That's *exactly* what I wanted. Normally, I say, "I owe you a beer," but in THIS case, I owe you a MARTINI (with the full shebang -- greek olive, orange slice, and the bowl of pretzels!). Of course, I *totally* can NOT understand why it works... it looks like the "secret" is that <div style="clear:both"> which, well, I don't know, how does one even come UP with something so non-intuitive.... it is akin to, "My car won't start," and then a stranger walking up and says, "needs a 2 inch yellow wire instead of the 1 inch black wire." I'm like, Huh? What? Why? Anyway, you fixed it! THANK YOU!!! p.s. I almost slipped back into 1990, and cheated by using <table><tr><td.... LOL
  6. And, no, that doesn't work at all. That ends up looking like (i put dots in it to separate my illustration here): 1 2......3 ........4 Again, I'm wanting 1.........2 3.........4 This is so d*** f****n complicated it's ridiculous. I'll just do a stupid table.
  7. Okay moderator, you're right. My bad.
  8. No, I need to know the principle. They are not 'really' images -- I just tried to make it simple for question/answer's sake. It's really a logo in upper left, a FAQ | Phone | Contact thingy in the upper right, a diagram below the logo, and a paragraph with words/bs underneath the FAQ/Contact thingy.
  9. Thank you for answering, but it does not work -- it does not pin image #2 in the upper right hand corner. Image #1: pinned all the way in upper left hand corner Image #2: pinned all the way in upper right hand corner ...and then, Image #3 directly below image #1, and Image #4 directly below image #2 See, that's the problem I'm been having -- getting #1, and #2 pinned into those corners. What can I change to make that work?
  10. I apologize in advance for such a dumb newbie question I have spent over 4 days trying to get my browser to display 4 images and CANNOT seem to wrap my brain around how to do it: Image #1: upper left hand corner. Image #2: upper right hand corner Image #3: directly below Image #1 Image #4: directly below image #2 I have tried every permutation of "float left/right," "position absolute/relative," etc., and can't make it work. This is what I want: My css code gets the first 2 images where I want them, but the remaining 2 images.... I'm drowning myself in beer right now... hellllllllpppppp <div style="margin:0px 0px 0px 0px;FLOAT:LEFT"> <img src="1.jpg"> </div> <div style="margin:0px 0px 0px 0px;FLOAT:RIGHT"> <img src="2.jpg"> </div> <div style="style=victorian era, with high heels... don't know what goes here to make it work "> <img src="3.jpg"> </div> <div style="no style, ran out of styling cream "> <img src="4.jpg"> </div> THANK YOU!!!!
  11. Oops, sorry I didn't articulate my question very well. I didn't want just one image to commandeer an entire line. Rather, like this (I sketched an image):
  12. Sorry for the really, really basic CSS question. (I'm asking this in the PHP forum, because so far, you've all been nice to me and haven't made fun of some of my really dumb questions.) Image #1 is in the upper left corner of my browser. Image #2 is in the upper right hand corner of my browser. How do I get Image #3 directly below Image #1 and Image #4 directly below Image #2 It should look like this: 1 2 3 4 But no matter what I do (group them into bigger divs, or make position absolute or relative, etc., etc.) what happens is that #3 and #4 get stuck between, or looks goofy. <div style="margin:0px 0px 0px 0px; float:left;"> <img src="1.jpg"> </div> <div style=" margin:0px 0px 0px 0px; float:right;"> <img src="2.jpg"> </div> <div> <img src="3.jpg"> </div> <div> <img src="4.jpg"> </div> Thank you, in advance, for helping!
  13. Thank you for all the replies! Okay, it just became apparant to me that I should have explained all the details, my mistake. So, here goes: 1.) My machine has a mySQL database on it (all 3000 UPC codes, and their corresponding prices). 2.) Another website is #1 on Google, and gets a BAZILLION queries per second. 3.) I provide MY page as an "API page." In other words, when THEIR machine gets a query (e.g. requesting a Price for a particular UPC code), THEIR machine queries MY machine. 4.) Rather than having THEIR machine cause MY machine to do a mySQL lookup a bazillion times a second, I thought it would be faster if my "API page" had a simple Array on it (the Array I described), to provide the result (the "price") for the UPC queries. Now, I'm wondering if I should just "get rid" of the entire array, and have it so when their machine queries MY machine, my machine does a mySQL lookup each time. When THEIR machine accesses my API page (with the big array on it), I always "assumed" that their machine loads my Array into its memory..... but I don't know for sure, I have no way of knowing, and I cannot control whether it does, or does not. My goal is to provide the quickest result possible. Important: When THEIR machine queries my machine, as well as a whole bunch of other websites like mine, whoever returns the result the FASTEST gets on the top of their result list. So, I have an incentive to make my machine provide a result faster! (If a competitor's machine takes 3 billionths of a second to produce a result, I want my machine to only take 2 billionths of a second).
  14. I have a 5000 item array of grocery UPC numbers and prices (here's a snippet): $myarray = array( '3540132662329' => '74.46', '8870132664186' => '63.24', '1090132664313' => '79.56', '6550132671425' => '46.92', '0020132685310' => '37.74', ); When someone inputs a UPC number, a price shows up: echo $myarray["6550132671425"]; // echoes 46.92 Is there anything FASTER than using an array? For example, converting the array into a string like this: $mystring = " 3540132662329-74.46, 8870132664186-63.24, "; ...and then using string functions like strpos, and substr to parse out the price? Or is it better to stick with arrays?
  15. Thank you, Requinex! You have saved my bacon MANY times now! I sure appreciate it! One non-alcoholic beer comin' right up!
  16. Nope, still BIG problem. On your computer, create a text file called "bigfile.txt" with ONE string on it, exactly: Very Good Ethics Code CODE CODE. Now, I run this code (I didn't leave anything out): <?php #again, "bigfile.txt" is a text file with this exact string: Very Good Ethics Code CODE CODE. $lines = file("bigfile.txt"); foreach ($lines as $n => $line) { $line = preg_replace('/code(\s+code)+/i', "code", $line); } file_put_contents("bigfile.txt", $lines); ?> Nothing got changed (here's the output): Very Good Ethics Code CODE CODE. If you help me with this, I will buy you a beer (non-alcoholic, because I'm a goody-goody person) if you ever come to my hometown!
  17. For some reason, this doesn't work: <?php $string = 'You have a code CODE code of ethics'; while (preg_match("/code\s+code/",$string)) { $string = preg_replace("/code\s+code/","code",$string); } print $string; ?> I don't want to replace all instances of duplicated words, rather, only when the word "code" is duplicated. Throughout my 100mb text file, the word "code" appears duplicated (with varying whitespace between). For example: From this: You have a code CODE code code of ethics. Code code Code green means everything is okay. What is the CODE code code code for the lock. To this: You have a code of ethics. Code green means everything is okay. What is the code for the lock. But for some reason, I cannot get my preg_replace to work?
  18. Dr. David Annis, thank you -- but the problem I'm having comes from PHP wanting to replace the "wheel" that comes before the "cat". (haha -- it's kinda funny, you gotta laugh.... we're talking about cats and strig, got a whole zoo goin' on in here LOL) So anyway, if my original string is $string = "The wheel is too big for the cat's wheel"; I only want to replace the "wheel" that comes AFTER the word "cat." $corrected = "The wheel is too big for the cat's tire"; Your code suggestion will first look to see if "wheel" comes after "cat" (yes, it does), and then the string-replace will replace all occurences of "wheel," which is not what I want (I only want to replace the instances of "wheel" that come after "cat." MY code -- from my first post: $fixed = str_ireplace('wheel','tire',substr($original_string,stripos($original_string,'(W'))); -- WILL *ALMOST* work... but what happens is that it "cuts off" the first part of my string. So, in a nutshell (laymans terms), how to we make PHP only replace a string that comes after another given string?
  19. So, here's what I'm trying to accomplish: to loop line by line through all 500,000 lines. Any time the word "wheel" occurs AFTER the word "cat", I want it replaced with tire: Original: The cat jumped over the wheel. My four wheels are cool. My car has a wheel and a cat on another wheel. Desired result: The cat jumped over the tire. My four wheels are cool. My car has a wheel and a cat on another tire.
  20. Hi again! Thank you for helping me yesterday! Regarding replacing with "(w/tire)," no that won't work because sometimes it's different words after the "w/" (for example, w/ door, w/ hood, etc., and since it's a 100mb text file with 500,000 lines, I won't be able to write a specific str_replace for each one, especially since I don't know, ahead of time, what comes after the "w/" part). I know I'm not articulating the reason "why not" very well, but I know that once I have a line of code, I can then apply the "principle" to all the other str_ireplaces that I have to do. Oops something just occured to me -- UNLESS I loop "line-by-line" (like when you helped me yesterday), PHP will treat all 500,000 lines as ONE BIG STRING, and if we say "any occurence of 'wheel' as long as it's after the "W/," then that won't work because with str_ireplace, it will do the ENTIRE FILE after the very first "W/" thingy, right? Uh - oh So, I guess that leaves using preg_replace (and I don't want to do that because I am terrible at preg stuff), and looping line-by-line, right? (Unless I am TOTALLY goofy-wrong on this, or unless you're seeing something I am missing?) Anyway, I NOW KNOW how to loop line-by-line (because you taught me how yesterday *yeah!*), so I'll put the str_ireplace in my "loop line by line" code. I just don't know how to fix my code without making it cut off that first part. My brain feels really really small right now
  21. May I please ask one more question? About replacing a string only if it appears *after* a particular string? I'm having trouble replacing all occurrences of "wheel" with "TIRE" but only when the word "wheel" is after this: (W/ Example: From this: A large wheel is shiny. Big 4 wheel truck (W/ wheel) Car with a wheel, and a small toy (w/ wheel) Four wheelers are cool To this: A large wheel is shiny. Big 4 wheel truck (W/ TIRE) Car with a wheel, and a small toy (w/ TIRE) Four wheelers are cool Unfortunately, I thought this worked: $fixed = str_ireplace('wheel','tire',substr($original_string,stripos($original_string,'(W'))); ...until I realized it was *cutting off* all characters up until that first '(W/' What can be done to make this work?
  22. Thank you, y'all! The code actually works: <?php $lines = file("animals.txt"); foreach ($lines as $n => $line) { if (stripos($line, "cat") !== false) { $lines[$n] = rtrim($line) . " Be careful with cats!" . PHP_EOL; } } file_put_contents("animals.txt", $lines); This is the FIRST forum I have ever asked a question to where it just gets answered, I cannot believe it! Thank you all so much! Usually, well, NOT "usually".... ALWAYS, this is what happens: Me: How do I make PHP loop line through line? 1st response: "Why do you need to loop line by line?" 2nd response: "Google FOPEN" 3rd response: "This can be done in Perl" 4th response: "It's just simple loops" Me: I cannot figure out how to loop line by line. 5th response: "What kind of project are you working on?" Me: It's complicated, I just can't figure out how to loop. 6th response: "This isn't a 'free coding' help center, you need not be rude. Me: I wasn't rude. 7th response [moderator]: Saying you're not rude, is rude. You are now banned So, I think I've finally found a decent forum! Thank you, everybody!
  23. Uh-oh, for some reason, your code doesn't work (none of the lines get changed). I thought it was because you have "$lines" plural, (so I made it $line), but it still doesn't work. I'm staring at it and staring at it, but my mind is as blank as a cloud right now, I can't figure it out?
  24. I'm so sorry to ask such a "newbee question," but believe me I have been on Google for the better part of the week trying to find an answer. I'll start with the brief question. Then I'll give an example to show what I mean. Then, I'll give the BESTEST "pseudo-code" I could come up with (to PROVE that I've really given it my best). Question: How do I make PHP loop through a big file, make the changes line by line, and to save the resultant file. Example: I have a 100mb text file ("animals.txt") with 500,000 lines. If any lines have the word "cat" in it, I want to add "Be careful with cats!" to the end of the line: From this: A fish and his tank. A cat and his toy. A bird and her cage. A frog and his lilly. A cat and her friend. To this: A fish and his tank. A cat and his toy. Be careful with cats! A bird and her cage. A frog and his lilly. A cat and her friend. Be careful with cats! The best "pseudo-code" I can come up with is: <?php $data = file_get_contents("animals.txt"); $lines = explode(PHP_EOL,$data); foreach($lines as $line){ if(stristr($line,'cat')) { $line = $line.' Be careful with cats!'; } $result .= $line; fwrite($result,'MyNewFixedFile.txt') ?> I know this looks like a long drawn out question, but I worked really hard on trying to figure it out myself, and I worked really hard on making it concise and easy to understand. Would someone please tell me what to do to make this work? Hopefully, my "pseudo-code" is close to being correct. But if it's totally horrible, I don't have any ego in this one, so you can tell me it is horrible and I won't take it personally. THANK YOU!!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.