Conditional subpatterns It is possible to cause the matching process to obey a subpattern conditionally or to choose between two alternative subpatterns, depending on the result of an assertion, or whether a previous capturing subpattern matched or not. The two possible forms of conditional subpattern are (? If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used. There are two kinds of condition. The first part matches an optional opening parenthesis, and if that character is present, sets it as the first captured substring. If the condition is the string (R), it is satisfied if a recursive call to the pattern or subpattern has been made. If the condition is not a sequence of digits or (R), it must be an assertion. (? The condition is a positive lookahead assertion that matches an optional sequence of non-letters followed by a letter.
Ajax upload with XMLHttpRequest level 2 and the File API | Phil Parsons I’ve put together a micro Ajax library for the XMLHttpRequest level 2 spec. You can go check it out on Github or read the related article XMLHttpRequest Level 2 Ajax library, xhr2-lib Ajax applications are wide spread these days and one thing that has proven a pain in the arse is uploading files. I’m sure most people will have fired off a fake asynchronous upload to a hidden iframe or used a sneaky swf to handle it but now with the development of the level 2 specification for the XMLHttpRequest object some of those woes may soon (if you are ok about not supporting IE) be a thing of the past. The FileReader API and the DataTransfer object One of the coolest things I’ve messed about with so far in HTML5 is the FileReader and File APIs and their ability to read in files from the users computer. XMLHttpRequest object send() with File In the level 2 specification the send method can accept a File object argument which allows us to stream binary chunked data to the server asynchronously. Summary
mod_rewrite cheat sheet | mod_rewrite reference with useful examples. method_exists() vs. is_callable() One thing I often see when re-factoring PHP applications, is the improper use of the method_exists() function, and I think this needs a little bit of clarification. Here is a typical example of what I’m talking about: The purpose of this code snippet is quite easy to understand (even if I don’t encourage to do this kind of not-very-OOP-stuff): having an object named “$object”, we try to know if it has a method named “SomeMethod”, if so, we call it, and provide some arguments to it. This code will probably run very well during all its lifetime, but what if the object’s method is not visible from the current scope (like… a private or protected method)? The real intent of the previous code snippet was in fact to know if the application could call a method on the object, from the current scope. This is why (among other reasons) is_callable() is part of the PHP built-in functions. Here is another snippet of code to illustrate the differences between method_exists() and is_callable() in action:
Caching API responses with PHP | Phil Parsons Most websites have some kind of widget that fetches data from an external RESTful API provided by services such as Twitter, Flickr and Facebook to name just a few. These APIs often limit the amount of hits any one Domain/IP can make and if you go over your rate limit then pow, no data for you and an empty widget. This PHP class gives you a mechanism to cache your API responses locally and only update them on a set time interval so you always stay within the rate limits for each API call you make from your site. API_cache.php The class accepts a URI for your API call, a filename to write to (if this is not in the same directory as the class you will need to make sure that directory exists), and a time period for how long you wish to cache the response for. Using the API_cache class effectively Here is an example usage of the class taken from the demo.
HTML Purifier - Filter your HTML the standards-compliant way! DomainByIP.com - Find websites hosted on the same IP-address Special effects using imagefilter() | Practical PHP Programming bool imagefilter ( resource image, int filter_type [, int parameter1 [, int parameter2 [, int parameter3]]]) The filters described here were written for the PHP-bundled build of GD, and may not be available in other releases. This is quite an odd function, as it happens, because the number of arguments you need to pass to it vary depending on the effect. The best way to explain this function is simply to explain briefly how it works then show a code example, so let's get started straight away. No matter what, the function returns true if the filter was applied successfully and false otherwise. First up is IMG_FILTER_BRIGHTNESS, which takes a number between -255 and 255 that represents how much you want to brighten or darken the image. This code example will lighten our space picture just a little: Next up is IMG_FILTER_COLORIZE, which takes three parameters between -255 and 255 that respectively represent the red, green, and blue values you want to add or subtract from the image. Jump to:
3 Solutions for Supporting Internet Explorer In the beginning, Internet Explorer was the progressive browser. After a period of inactivity, Internet Explorer became the bane of our existence. Microsoft has since recommitted to their browser but the fact remains that sometimes modern Internet Explorer is lagging just a bit behind WebKit-based browsers and Firefox. We also need to accommodate for earlier versions of IE. The following will allow your sites to quickly and almost magically work better in Microsoft's flagship browser! htmlshiv.js Remy's HTML5shiv creates HTML5 elements like main, header, footer, etc. via JavaScript. selectivizr.js Selectivizr.js is an incredible resource, polyfilling loads of unsupported CSS selectors and properties, including the all-important last-child. An absolute must for your modern projects. <html> Conditional Comments The ugliest conditional comment series you'll ever see. This snippet doesn't require or wait on JavaScript, and isn't near the weight of a JavaScript library.
requestAnimationFrame for smart animating If you’ve never written code to animate inside the browser, you can stop reading :) What is requestAnimationFrame? In your animation work, you’ve used a timer loop to make changes every few milliseconds. Why should I use it? The browser can optimize concurrent animations together into a single reflow and repaint cycle, leading to higher fidelity animation. OMG I can brag about having a site with battery-friendly animations? Yeah bro. How should I use this? Note: I am using ‘requestAnimFrame` here because since the spec is still in flux, I don’t want to make a straight polyfill, yet. 2012.01.07: The spec has gotten some fixes and settled down. A robust polyfill Opera engineer Erik Möller wrote about rAF and developed a polyfill that better handles browsers without native support. I have this polyfill available as a gist as well. Let’s see that in action The requestAnimationFrame API The callback is passed the current time as the first argument, as you’ll likely want that. Is it ready?
Advanced PHP Error Handling via htaccess In my previous article on logging PHP errors, How to Enable PHP Error Logging via htaccess, we observed three fundamental aspects of preventing, preserving, and protecting your site’s PHP errors: Prevent public display of PHP errors via htaccess # supress php errors php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off php_value docref_root 0 php_value docref_ext 0 Preserve (log) your site’s PHP errors via htaccess # enable PHP error logging php_flag log_errors on php_value error_log /home/path/public_html/domain/PHP_errors.log Protect your site’s PHP error log via htaccess # prevent access to PHP error log <Files PHP_errors.log> Order allow,deny Deny from all Satisfy All </Files> Now, in this article, we will explore these operations 2 in greater depth, provide additional functionality, and examine various implications. Controlling the level of PHP error reporting # general directive for setting php error level php_value error_reporting integer Useful Links
Broken Link Checker Tool - Dead Link Checker Worried about broken links affecting your website's usability and rankings? Site Checker is a free tool, which crawls through your website identifying broken links for you to fix. Multi Check enables you to run Dead Link Checker through multiple websites in one go. Our most popular service is Auto Check, which runs Dead Link Checker through your website(s) on a regular basis and emails the reports to you automatically. Why are broken links bad? They negatively impact usability - resulting in reduced traffic and conversions.They damage your rankings - by preventing search engine website crawlers from indexing pages. Site Checker is a simple solution for webmasters and SEOs Identifying broken links on your website is easy and free. To access the multi-site checker or auto checker, first or
Measure When you measure your site, web.dev uses Lighthouse, an open-source, automated tool for improving the quality of web pages. Lighthouse will audit your site in the following categories: Performance Audits for metrics like first paint and time to interactive to determine lag. Best Practices Looks for everything from HTTPS usage to correct image aspect ratios. Checks for best practices to ensure your site is discoverable. Accessibility Checks for common issues that may prevent users from accessing your content. All tests are run using a simulated mobile device, throttled to a fast 3G network & 4x CPU slowdown.
Color Wheel - Color Calculator | Sessions College The color wheel is a chart representing the relationships between colors. Based on a circle showing the colors of the spectrum originally fashioned by Sir Isaac Newton in 1666, the colour wheel he created serves many purposes today. Painters use it to identify colors to mix and designers use it to choose colors that go well together. The classic color wheel shows hues arranged in a circle, connected by lines or shapes. The colors include primary colors (red, yellow, and blue), secondary colors (orange, green, and violet), and tertiary colors (yellow green, blue green, blue violet, red violet, red orange, and yellow orange).Secondary colors are created by mixing primary colors. For example, mixing red and yellow creates orange; mixing yellow and blue creates green. The color wheel is a chart representing the relationships between colors. The classic color wheel shows hues arranged in a circle, connected by lines or shapes.