Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. Your regular expression is malformed, it will thrown an E_WARNING (which your error reporting should be displaying!) stating as much. One way to access those values with a regular expression is: $places = array(); if (preg_match_all('/^\["([\pL ]+)",/mu', $subject, $matches)) { $places = $matches[1]; } print_r($places); The expression looks for "the start of a line, followed by the characters [", followed by one or more unicode letters or ASCII space characters (these are captured for use later), followed by the characters ",. The pattern modifiers mu ask the matching engine to use multiline mode (so ^ matches at the start of any line rather than just the start of the entire string) and UTF-8 mode (so non-ASCII characters can be matched easily).
  2. The string "0" is considered as empty (i.e. empty("0") returns TRUE). In the first if statement you could either explicitly cater for "0" or use some other method to check on the string being really empty (e.g. strlen to check the length of the string [in bytes]).
  3. If you'd like a more in-depth (baby steps) explanation, do let us know and someone will be along to help you out.
  4. The p probably refers to an aliased table name (FROM mytable p) and the '%$searchKey%' is a mixture of two things: firstly, the value of the $searchKey variable is substituted into the string (if $searchKey is blah then the string is '%blah%'), then that value is used as a parameter for MySQL's LIKE operation. See the LIKE man page.
  5. The error states that access to files using an URL is disabled in the config. Turn on (or set to 1) the allow_url_fopen setting in your php.ini (details). Were you not getting this error with the XML URL?
  6. Why not use their JSON API to save you parsing and extracting the XML data into an array; you could then just use json_decode and voila an array (or object if you want). Change the API URL to use output=json instead of output=xml.
  7. You could also replace the return statement in rajivgonsalves' function with the similarly functioning: return strspn(strtolower($word[0]), 'aeiou') ? 'an' : 'a';
  8. Not by default, no. Yes, both, just to see what is happening.
  9. Define "cannot view": are there any errors reported and/or logged, does nothing at all happen, is your server noticing the requests and sending a response, etc.?
  10. thorpe, the OP wants to be able to determine whether "an" or "a" should preceed a word. For example given the words apple, banana, orange the correct choices would be an, a, an respectively.
  11. Out of interest, is the entire subject string that you're matching against just this tags/content combination? I.e. does the subject string start with the charset tag and end with ?= and there's only one of it?
  12. [ot] That'll be a positive lookahead, looking for ?=[/ot]
  13. How many queries do you have that means it's more attractive to hack something together than just go and edit the queries directly? That's quite apart from questioning why every single table and every single query would need a fixed column/value pair throughout your entire application. I'm all for helping you to solve a puzzle (inserting a string into some other strings) but don't want you to be entirely wasting your time.
  14. salathe

    Sup

    Hi Taz, welcome to PHPFreaks. Settle down and enjoy the ride.
  15. If deck A had two cards and B ten cards, would the chances of getting a card from A or B still be equal?
  16. Regarding pattern delimiters, there is now a page about them in the manual: http://php.net/regexp.reference.delimiters (no more linking to "the first paragraph in the introduction"!)
  17. Your permissions look to be too restrictive, only the file owner can write to it and the chances are that user is not the same as the user that PHP runs as. Either change the ownership of the file, or use looser permissions (e.g. 0777).
  18. Maybe, have a look at the data in the database and see if there are extraeneous slashes.
  19. Are you sure the problem doesn't lie with the data in the database rather than with the JSON encoding?
  20. To avoid replacing already replaced values, you could instead use the strtr function.
  21. salathe

    Regex

    Yes, but what is it?
  22. salathe

    Regex

    What is the $string that you're using?
  23. gizmola, given the text from your last post, EchoFool doesn't want " wasup guys!" to be one of the items since it is not surrounded by # characters.
  24. As much a fan of regular expressions as I am (ask anyone here), sometimes basic string functions will suffice. Indeed, there are a number of different string functions that could be employed here to do the job! Coming to the rescue today is the under-rated and misunderstood strtok function. The snippet below takes the (x)path and hunts around for the first item and then "everything else", allocating those values to their appropriate variable. $path = '/root/section/subsection/etc'; $first = strtok($path, '/'); $rest = '/' . strtok(''); var_dump($first, $rest); If you really want a regular expression solution, or don't really feel like using strtok and would prefer other string functions, do let us know.
  25. How about the following? $str = 'abc#username#username2#foo'; // Here's the magical voodoo!.. $split = array_slice(explode('#', $str), 1, -1); print_r($split); /* Array ( [0] => username [1] => username2 ) */
×
×
  • 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.