Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. I know the topic is marked as solved, but since you're using PHP 5.2.9 you could also be making good use of the DateTime class (available as of 5.2.0). For example: $tz = new DateTimeZone('UTC'); $date = new DateTime('18:00:00', $tz); $end = new DateTime('20:45:00', $tz); $times = array(); while ($date->format('U') <= $end->format('U')) { $times[] = $date->format('H:i'); $date->modify('+1 minute'); } print_r($times); Aside: Some classes were introduced in PHP 5.3 to work with periods and intervals of time (DatePeriod and DateInterval respectively) but since you're not using that version, the above code snippet will suffice.
  2. I think the purpose of an offtopic block would be to make it less visible than the regular post text. Sitepoint draws attention to their offtopic blocks by changing the background colour, but also makes the text smaller so it's easier just to gloss over the block. Offtopic: In the mean time, there's nothing stopping you from formatting posts in a similar style, albeit without a coloured background. An [ot] bbcode would make things easier though. P.S. Hi.
  3. DOMDocument::getElementById returns NULL if there is no node with that ID, so check for NULL before trying to access any properties (like nodeValue).
  4. I know this topic is marked as SOLVED already, and that manually playing with the XML will get the job done. However, when working with XML documents, it would be advisable to use a proper XML parser (there are a number of different approaches in PHP). Using one would make this CDATA problem a non-issue since the parsers will properly handle that type of XML node.
  5. Please read the note that was attached to my post.
  6. Rather than manually creating an array of the files, why not just use the iterator_to_array function to do the hard work for you? Of course that would include dots/directories too, but a quick filter would sort that out.
  7. It simply encodes non-URL-safe characters into ones which are URL-safe using a widely accepted method (% followed by hexadecimal representation of the character). It has nothing to do with security or obfuscation of data. See: http://php.net/urlencode
  8. The whitespace nodes between the normal nodes (config, etc.) still count as nodes when you're traversing through the childNodes collections. The following (untested) should be what you're after: var petrol_price = XMLDoc.getElementsByTagName("config")[0].childNodes[1].childNodes[3].firstChild.nodeValue;
  9. As you can see, when using DOMDocument::loadHTML with no doctype present then it will automatically add the HTML 4.0 Transitional doctype to the document. As far as I'm aware, there is no flag to turn this behaviour off. If you want to find out the presence of a doctype then it might mean manually inspecting the source HTML (doctypes need to be at the beginning of the source so it's not too difficult).
  10. Note that if you only want the zeros to be trimmed off of the end of the string, then you should really be using the rtrim function instead trim (the latter trims from both sides).
  11. It's not a full script but the examples on the page Yesideez mentioned, or those on the manual page for SplFileObject::fgetcsv might be useful.
  12. The replacement could be done pretty easily with preg_replace_callback. Something like: echo preg_replace_callback( '#\beval\(base64_decode\("([a-zA-Z0-9+/]+=*)"\)\);#', function ($m) { return base64_decode($m[1]); }, $file ); Note: The anonymous function is only available as of PHP 5.3, prior to that you could either use a normal named function or create_function (e.g. create_function('$m', 'return base64_decode($m[1]);'))
  13. mktime can help - http://php.net/mktime Something along the lines of: $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
  14. First, I know this thread is marked as SOLVED already. I'm new to the forum and if it is considered bad etiquette to reply to solved threads then please do let me know! On to the reply. It would be possible to construct a regular expression to check the conditions (as you requested): Starts with alphabetical character Contains only alphanumeric, ".", "-" or "_" characters Has a maximum length of 15 characters Contains only one ".", "-" or "_" character However that pattern might not be particularly understandable at a glance (or even after careful consideration!) when looking through the code. My suggestion would be to break things down into at least two sections. [*]Have a nice, simple regex to check that the string starts with [a-z], only contains [a-zA-Z0-9.-_] and has a max. length of 15 characters. [*]Check for only one ".", "-" or "_" character. That could be achieved by: if (preg_match('/^[a-z][a-z0-9._-]{0,14}$/Di', $user) && preg_match_all('/[._-]/', $user, $matches) <= 1) { // ... } If you must stick to only one regular expression (perhaps just for educational purposes) then you might use the following if you want to have a stab at deciphering what it's doing! /^(?=[a-z0-9]*+[._-]?[a-z0-9]*+$)[a-z][a-z0-9._-]{0,14}$/Di
  15. Whilst it makes no real difference at all, I'd rather pass a string to parse_str at all times. If parse_url cannot find a query string, it returns NULL which is then cast to an empty string. So, no requirement to cast to a string just a personal choice at the time.
  16. Do you really need regular expressions for this? From what I gathered from the first post, the following should be what you are wanting: to get at the query string items in each url. $urls = array( 'http://www.northfieldhouse.leicester.sch.uk/parents.php', 'http://www.northfieldhouse.leicester.sch.uk/parents.php?action=Letters%20Home', 'http://www.northfieldhouse.leicester.sch.uk/parents.php?action=Previous%20Letters&menu=Letters%20Home' ); foreach ($urls as $url) { // Get query string portion of URL $query_string = (string) parse_url($url, PHP_URL_QUERY); parse_str($query_string, $query_array); // Pad with default values $query_array += array('action' => '', 'menu' => ''); echo '<h3>', $url, '</h3>'; echo '<pre>', print_r($query_array, TRUE), '</pre>'; }
  17. Other ways to get at the same variable would include: ${0}, ${00}, ${11 - 6 - 5}, ${substr('120', -1)} (ie, anything that results eventually in string value of "0"). You can't go via the $GLOBALS array as the key ($GLOBALS["0"]) is cast as an integer and $GLOBALS[0] does not exist and of course you cannot use $0 as that is an invalid variable name and will throw a parse error. Good to see my blog getting a search engine visitor.
×
×
  • 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.