Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. \n\r is not a usual line ending sequence. They're: \r\n - "Windows" \r - "Macintosh" \n - "Unix"
  2. You could use explode. For example, explode(" ", "a b c") gives an array containing a, b and c.
  3. eli_4benett, that's not how feed readers work (though some will reflect the change).
  4. Hehe no worries davey. Don't forget to mark the topic solved if it is.
  5. To manipulate the value in the replacement (i.e. what becomes the <a> tag) you can use a callback like: function makeLinkFromMatch($match) { $link = $match[1]; $text = str_replace('-', ' ', $match[1]); return sprintf(' <a href="%s">%s</a>', $link, $text); } You would then need to change preg_replace to instead use preg_replace_callback: $text = preg_replace_callback('/ link:(\S+)/', 'makeLinkFromMatch', $text); If you haven't use preg_replace_callback before, it may be a little confusing so do check out the documentation for it and ask here if you're unsure.
  6. This looks to be something that can be done much simpler, for example with basic string functions, assuming that the subs file follows a (new line) pattern consistently. Is there any particular reason why you've chosen to use strict matching against the lines' values with a regular expression?
  7. The print out does not show an array containing arrays, but rather an array containing objects. There are lots of ways to do what you want, but a simple one would be: data = array( (object) array('id_distrito' => '01'), (object) array('id_distrito' => '04'), (object) array('id_distrito' => '11'), (object) array('id_distrito' => '13'), ); $contains = FALSE; foreach ($data as $object) { if ($object->id_distrito === '11') { $contains = TRUE; break; } } If $contains is true after that, the array contains an object with id 11.
  8. Not without seeing what you're currently doing (some code please).
  9. Depending on how restricted the input is, you'll probably want to use the limit parameter for explode as well: // Limit to two parts so "John Smith Jnr" becomes "John" and "Smith Jnr" list($first, $last) = explode(" ", $fullName, 2);
  10. Just change the 1 in {1,30} to 0.
  11. Here's a loop which outputs some of those values, it should give you an idea of what to do. $json = '[{"domain":"testdomain","tld":".net","result":"Taken"},{"domain":"testdomain","tld":".com","result":"Taken"},{"domain":"testdomain","tld":".mobi","result":"Taken"},{"domain":"testdomain","tld":".biz","result":"Taken"},{"domain":"testdomain","tld":".info","result":"Taken"}]'; $data = json_decode($json, TRUE); foreach ($data as $domain) { echo $domain['domain'] . $domain['tld'] . ' is ' . $domain['result'] . '<br>'; }
  12. You'll probably want to count($flickrfeed->photos->photo)
  13. PHP has JSON support: see http://php.net/json
  14. You can convert the JSON string into a PHP array (or object, if you want) then count and/or loop over that. Take a look at the json_decode function.
  15. Don't use array_flip() if multiple items can have the same value... when flipped items will be lost! array_keys() is where the fun is at.
  16. 1) It is accurate and complete in the sense that it will do something specific. Whether that something is precisely what you want is another matter entirely! For example, email addresses are allow to use the plus character (+) for the mailbox part (before the @) but your regex does not allow it. There is also no check at the end of the regex for "other stuff" so the string "[email protected] this is not part of an email address" will still return true! 2) Regex are good for consisely matching sometimes complex patterns that might be otherwise difficult to match. In the end, it is just another tool to get a job done and should be considered globally better than other approaches doing the same task. P.S. Like I mentioned in point 1, there are a number of issues with your particular regex which really should not be done. Things like wrapping the character classes in parentheses are just not necessary. I'm not sure if you would want a post picking apart the regex so will stop there excepting to say that validating emails with regex has been done a million times and most of the time someone else's "solution" might not be appropriate for your script.
  17. Perhaps you're looking to use setAttribute (or .value directly if you want to be old-school)?
  18. json_encode was only added to the PHP core in 5.2.0. You can* install the json PECL package (http://pecl.php.net/package/json) but it would be advised to push your client into upgrading their super-duper-old version of PHP to something more recent (with many hundreds of security and bug fixes). * if you cannot even add pecl extensions, push even harder for an upgrade... tell them you can't do your job with that rubbish old version. [ot]Generally the PHP manual displays the version information at the top of the page for each function: http://php.net/json_encode for example.[/ot]
  19. [ot] It does return values. Behaviour is FALSE on error (and a warning is issued), 1 for a 'normal' include or whatever if the included file uses return "whatever";[/ot]
  20. Or using pretty classes: $tz = new DateTimeZone('Etc/GMT-3'); $dt = new DateTime('now', $tz); echo $dt->format('r'); //Thu, 18 Feb 2010 15:33:39 +0300 (Edit: typoed "Our"... grr)
  21. Or you could just remove the last line from the $lines array with array_pop
  22. djbuddhi: http://www.symfony-project.org/doc/1_4/ [ot]Please consider starting a new thread next time. This thread is 3 years and 4 months old.[/ot]
  23. Are you sure that that really does what you want? With that code, only the first /name/affiliation node will have its value set to hello regardless of how many name elements there are. Would it be right to assume that you wish to change the affiliation value for all of the name nodes having an @id greater then zero?
  24. [ot]Wow, guys give up already. You've been shown the problem and even (I think) found a solution. You're bumping this thread to the top of the list with nothing worthwhile to add to the topic. (Oops, so did I! )[/ot]
×
×
  • 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.