Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. I take it you no long want to parse the text file, or would you still like to do it as an academic exercise?
  2. I think you should instead be using the FILE_IGNORE_NEW_LINES flag in your call to file. That will remove the newline from the end of each line in the $lines array.
  3. It might help, or it might not, but could you give some example filenames (and any other information you think might be relevant) which are mistakenly ignored?
  4. That's the "error-control operator" and more information can be found in the PHP manual here: http://php.net/operators.error-control
  5. Wordpress.com?
  6. Merry Christmas to everyone.
  7. The single pipe is used for bitwise operations (working on binary), the double pipe is used as Maq said for logical operations; the '|' in your example, as Maq also said, isn't any special syntax, it's just that character in a string.
  8. Adding anything else to it seems to crowd the button too much (but, I am not an artist!!); I also tried just having "<?" but a) short tags are always controversial and b) I'm not sure if folks would "get" that that's a PHP button.
  9. How about ?
  10. And ask for Mastering Regular Expressions for Christmas.
  11. Do you need to use regular expressions for this? It would be much easier using a proper parser.
  12. What have you got so far?
  13. Sure, there are a couple of options (which can be tweaked depending on needs): 1. Match any single non-lowercase-character: /[^a-z]/ 2. Match only if all characters are lowercase: /^[a-z]+$/D
  14. You could also use: <?php $str = 'iamacr4zyfilename.jpg'; $ext = '.' . pathinfo($str, PATHINFO_EXTENSION); echo $ext; ?>
  15. You could implode the array, or to save repeating yourself could use a loop to go through the array and echo each value individually.
  16. Of course! One way would be to first construct a nice array which has the structure that you're looking for (grouping items by their category) and then simply loop over that array writing out the optgroups.
  17. But... what didn't work? Are you trying to simply count the number of characters in a string (e.g. "This is a string" has 16 characters) or the number of occurrances of characters, or...?
  18. There not only space whitespace characters in that string; there are also tab characters. Substituting space for [sPC] and tab for [TAB] the string is DATE:[sPC][TAB]2009/05/03[sPC][sPC][TAB]Hello:[TAB]WORLD (according to what I could copy/paste from your post). If you want to split on any whitespace, use a regular expression like /\s+/ in split.
  19. So you want to remove everything except the file extension, or just certain things? Your desired result isn't very clear: could you give some examples of what goes in and you expect to come out?
  20. array_filter would be more appropriate in this instance, since the OP is looking to filter the array based on some condition (the associated file having certain contents). That said, it doesn't make sense to process these serially but perhaps the OP just needs something simple so lets not delve into that.
  21. If you're using PHP 5.3, date_diff otherwise let us know what version you do have and answers can be more tailored towards that.
  22. You're missing something: the pattern just attempts to match any one single lowercase letter within the subject string. It makes no attempt to check that all of the characters within that string are lowercase letters.
  23. It would "work" in the same way that rajivgonsalves's example also "works". They both do the job and also suffer from precisely the same problem: yours pretends to make an effort to filter the input (even though that doesn't help at all).
  24. There are a number of silly mistakes in your pattern; for example the hex character typoes \{xD7FF} and x{FFFD}, and it nukes the range \x20-\x7E which are perfectly normal, printable, safe, happy-in-XML characters. Can you links us to where precisely you got these ranges of characters from?..
  25. You could just foreach over the array and add the values up (into a new array) as you go. Have you tried anything like that?
×
×
  • 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.