Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. Perhaps I'm thinking too far outside of the box, but if this is really just a matter of moving (files in) a directory when a CRON runs, can't you just use shell commands to get the job done (thinking mv)? Needing to only move 30 files at a time is a very strange requirement, could you elaborate on exactly why that's a necessity?
  2. What permissions are on the file (desmond.txt) and the directory containing it (if that's not just httpdocs) and to which user and group do they belong?
  3. If you want to find out which OS the script is running on, examine the PHP_OS constant or call php_uname.
  4. Here's one way, the comments should guide you through what is happening but do feel free to ask about any particular things that might be unclear. // Get all lines from the file into an array // No newline character at end of each line, skip empty lines in the file $file = file('./demo.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // Get a random number (of lines to show, minimum 2) $num_lines = mt_rand(2, count($file)); // Get keys (line numbers) for $num_lines lines $numbers = array_rand($file, $num_lines); // As of PHP 5.2.10 $numbers will be sequential which we don't want, so shuffle shuffle($numbers); // Output something useful echo "Displaying $num_lines random lines" . PHP_EOL; foreach ($numbers as $number) { echo $file[$number] . PHP_EOL; }
  5. Do you want to get the first x lines in the file, where x is a random number? Or do you want to get x random lines from anywhere in the file?
  6. Be more specific with what you want to find/remove, what the bigger piece of text is and what exactly you want the end result to be. We're not mind readers.
  7. I found the Zend Framework had a much shallow learning curve than I was previously lead to believe and the huge library of components does come in useful rather than having to brew your own solution for common tasks. You also don't really have to use the Framework side of things, you could use a different framework (or non-framework) and just load Zend chunk if you find them useful. Another framework that you might not have looked at is Kohana, it's a small framework ("lightweight") that often requires you to put your thinking hat on and get writing code (c.f. using a ZF component) but covers some core aspects common in web apps and allows you to get moving quickly.
  8. PHP will convert spaces and dots (and certain other characters) with underscore for $_POST and family (I believe the reasoning is to make a valid variable name). Either be aware of this automated conversion and code your receiving script with it in mind, or make sure the variable name is 'valid' (in the sense that it won't get changed) in the form.
  9. I have a rep? Anyway, it is indeed good to always take a peek at the manual for the authority on things (and if the manual is wrong, file a bug report!). It is often my first port of call when answering a question (but shh, I'm giving away my secrets to answering Qs!).
  10. Heh, my mistake. Though I can honestly say, I've never used it... always !=
  11. Just access it with name[1]
  12. Can you show the byte values of the characters?
  13. ignace, <> is not a PHP operator.
  14. You won't be able to put a variable into that style of writing a regular expression and just providing it to replace will only replace the first instance of the word. Instead, create a RegExp object as below. var text = "hello peter, you are awesome."; var name = "peter"; var replace = "mark"; var regex = new RegExp(name, "g"); text = text.replace(regex, replace); Note that the variable's contents will be evaluated as a regular expression, special characters and all!
  15. You simply need to escape the backslash: "\\n"
  16. As you can see 'this' does not refer to the fadingImagesIn object, resulting in that error. To get the correct scope, you can create a variable referencing the desired 'this' and use that within the anonymous function in setTimeout, like: fadingImagesIn.prototype.timer =function(){ var self = this; // ... setTimeout(function(){self.fadeIn('logoDiv1')},1000); // ... }
  17. Can you give more details (a quick snippet example) of what you're trying to achieve, even if it doesn't work?
  18. It simply means "not equal", in MySQL it is the same as "!=".
  19. How about telling them you've been stuck in Research and Development for the past couple years so don't have anything to show them?
  20. Try, text = text.replace(/(?:, ){2,}/g, ', '); Terms to research are "non-capturing group" and "quantifiers"
  21. You're welcome, we're here to help; even if it's just knowing where to look. We also have a feature here where if a question is considered "solved" the thread authors can mark it as such. You just need to press the little green button labelled "mark solved" at the lower-left of this page.
  22. salathe

    Buu!

    As I said on IRC, welcome to PHPFreaks radikaalz
  23. mattal999, function array dereferencing is not implemented in PHP (there has been talk about it in the past, the RFC is currently "declined") so you can't access the 0th array item in that matter. Also, there is no need to nl2br+explode the entire post (which may, in theory, be huge) if all that is going to be used is the first line. So, on those notes, another way (of many!) would be something like: echo strtok($row1['post_text'], "\r\n"); [ot]Using strtok a lot today.[/ot]
  24. A common solution is to use the \b magical escape sequence which matches only at word boundaries, to quote the bible, "A word boundary is a position in the subject string where the current character and the previous character do not both match \w or \W (i.e. one matches \w and the other matches \W), or the start or end of the string if the first or last character matches \w, respectively." (\w matches a "word" character). E.g. /\bYou\b/ will match "You" in "You are awesome" but not "Yours sincerely"
×
×
  • 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.