Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Nikita Popov's Blog:
The true power of regular expressions
Jun 15, 2012 @ 13:42:57

Nikita Popov has a new (language agnostic) post to his blog today about one of the most powerful things you can use in your development - something that a lot of developers don't understand the true power of - regular expressions.

As someone who frequents the PHP tag on StackOverflow I pretty often see questions about how to parse some particular aspect of HTML using regular expressions. A common reply to such a question is: "You cannot parse HTML with regular expressions, because HTML isn’t regular. Use an XML parser instead." This statement - in the context of the question - is somewhere between very misleading and outright wrong. What I’ll try to demonstrate in this article is how powerful modern regular expressions really are.

He starts with the basics, defining the "regular" part of "regular expression" (hint: it has to do with predictability) and the grammar of the expressions. He talks about the Chomsky hierarchy and how it relates to the "regular" as well as a more complex mapping of expression to language rules. He talks about matching context-free and context-sensitive languages and unrestricted grammars as well.

tagged: power regular expression define theory context

Link:

Chris Roane's Blog:
What does it mean to be an Advanced PHP Programmer?
Jun 06, 2011 @ 14:42:28

In a new post to his blog Chris Roane has a few suggestions about advanced programming and what it might take to be considered an advanced programmer in any language.

On a previous post I had someone comment that they did not agree that the code implementation that was presented in the article was advanced (which was described in the title). They also claimed that I was not an advanced PHP programmer. This made me think. Not because my programming skill or knowledge was challenged. But because I’m not sure what makes code or a programmer "advanced".

He asks a few questions about the criteria for considering someone an "advanced programmer" including things like how fast or efficient they are, how much they make or the conference(s) they've been to. He points out that, because "advanced" is such a relative term, it's hard to put a finger on it. Being this hard to define (and mostly worthless even if it is) he suggests an alternative to trying to figure it out:

Instead of throwing around general terms in labeling code or other programmers, let’s come together and figure out ways in improving code together. Practical applications.
tagged: advanced programmer opinion criteria define

Link:

Jonathan Snook's Blog:
Multiple Validation Sets in CakePHP 1.2
Jul 23, 2008 @ 12:51:27

Jonathan Snook has posted two methods for creating multiple validation sets in the latest version of your CakePHP application.

In CakePHP, you define how your data should be validated by setting parameters on the validate property of your model. In version 1.2, there is an on option that can be set on a specific rule that, when set, is either create or update. [...] Despite that, I developed a slightly different approach that allows for different validation sets to be specified and to be cleanly separated from each other.

He overrides the validates() method with his own in a custom model in one of two ways - having the script check for a validation set for the current controller or by specifying it directly with a validationSet property. Code for both methods is included.

tagged: cakephp framework validation set detect controller property define tutorial

Link:

Hasin Hayder's Blog:
Web scrapping in a smart way, making a "Today in History" object in PHP
Apr 29, 2008 @ 15:27:41

Hasin Hayder has written up a quick tutorial for his blog that shows how to create your own "Today in History" page with details from Scopesys pulled with a little web scraping.

There are thousands of services available on web who are presenting interesting as well as education information which you can really integrate in your web page or make a nice widget and let others use them seamlessly with their content delivery platforms. In this article I am going to show you how you can make a nice Today-in-History widget with the help of the data provided in Scopesys.

He wisely recommends that you check one thing first about the content you're grabbing - the copyright it carries with it. This could get you into big trouble down the line depending on whose content it is. The actual script is pretty simple - he defines some constants as markers for where things start and stop in the HTML and then uses strpos to get the locations for his substr call to grab the segments.

tagged: todayinhistory widget copyright scopesys constant define substr strpos

Link:

WebReference.com:
The Building Blocks: Data Types, Literals, Variables, and Constants - Part 3
Jan 29, 2007 @ 17:44:00

WebReference.com has posted part three of their "Building Blocks" series - a look at data types, literals, variables, and constants.

In part three, they focus more on the last type of "block" in their list - the constant:

Some real-world constants, such as pi, the speed of light, the number of inches in a foot, and the value of midnight, are values that don't change. PHP not only provides its own predefined constants but lets you create your own. Using constants makes it easy to write and maintain your programs.

There's talk of the define() and constant() functions and a mention of some of the predefined and "magic constants" as well.

tagged: building blocks variable constant define magic building blocks variable constant define magic

Link:

WebReference.com:
The Building Blocks: Data Types, Literals, Variables, and Constants - Part 3
Jan 29, 2007 @ 17:44:00

WebReference.com has posted part three of their "Building Blocks" series - a look at data types, literals, variables, and constants.

In part three, they focus more on the last type of "block" in their list - the constant:

Some real-world constants, such as pi, the speed of light, the number of inches in a foot, and the value of midnight, are values that don't change. PHP not only provides its own predefined constants but lets you create your own. Using constants makes it easy to write and maintain your programs.

There's talk of the define() and constant() functions and a mention of some of the predefined and "magic constants" as well.

tagged: building blocks variable constant define magic building blocks variable constant define magic

Link:

Felix Geisendorfer's Blog:
Include only the JS you really need
Nov 20, 2006 @ 13:46:00

In his latest entry, Felix shares a quick tip for CakePHP users out there to help them reduce the sizes of their pages and speed things up a little bit by including only the Javascript that you really need as a method inside your controller.

The basic idea is the addition of two functions and a variable to set the jsIncludes value and an includeJs/excludeJs pair to do the actual loading. The result is a much cleaner call to includeJs when rendering the application that will automatically pull in the files specified.

So if up to now you've always included all JS for every page load, this might help to reduce bandwidth usage for both you, and the users of your application. I know this is not the most advanced solution one could come up with. [...] But then I decided that it's too simple a problem for that kind of bloat.

All of the code is included here.

tagged: cakephp javascript include define function variable controller cakephp javascript include define function variable controller

Link:

Felix Geisendorfer's Blog:
Include only the JS you really need
Nov 20, 2006 @ 13:46:00

In his latest entry, Felix shares a quick tip for CakePHP users out there to help them reduce the sizes of their pages and speed things up a little bit by including only the Javascript that you really need as a method inside your controller.

The basic idea is the addition of two functions and a variable to set the jsIncludes value and an includeJs/excludeJs pair to do the actual loading. The result is a much cleaner call to includeJs when rendering the application that will automatically pull in the files specified.

So if up to now you've always included all JS for every page load, this might help to reduce bandwidth usage for both you, and the users of your application. I know this is not the most advanced solution one could come up with. [...] But then I decided that it's too simple a problem for that kind of bloat.

All of the code is included here.

tagged: cakephp javascript include define function variable controller cakephp javascript include define function variable controller

Link:

PHPBuilder.com:
BitMasks: Emulate Unix Permissions in PHP (Quickly)
Aug 09, 2006 @ 21:01:53

Permissions in Unix-based systems have become one of the standard models for development all over the world. They're simple to learn and use while being extremely powerful at the same time. In this new article (as contributed by Eric Potvin) from PHPBuilder.com today, they bring this power to the realm of PHP with bitmasks.

Bitmasking is a very useful method to emulate Unix-style file permissions (read/write/execute for example). What's nice about a PHP implementation is that you can configure your own bitmasks and use them for any kind of permissions in your scripts and applications. The implementation is relatively simple as well.

They start by defining a few of the permission levels (add/delete/denied) in PHP constants before showing the bitMask() function you can use to check a user's permissions. They also include some simple pseudo-code to show how it's used. For more information, check out the complete article here.

tagged: bitmask unix permissions tutorial define constants bitmask unix permissions tutorial define constants

Link:

PHPBuilder.com:
BitMasks: Emulate Unix Permissions in PHP (Quickly)
Aug 09, 2006 @ 21:01:53

Permissions in Unix-based systems have become one of the standard models for development all over the world. They're simple to learn and use while being extremely powerful at the same time. In this new article (as contributed by Eric Potvin) from PHPBuilder.com today, they bring this power to the realm of PHP with bitmasks.

Bitmasking is a very useful method to emulate Unix-style file permissions (read/write/execute for example). What's nice about a PHP implementation is that you can configure your own bitmasks and use them for any kind of permissions in your scripts and applications. The implementation is relatively simple as well.

They start by defining a few of the permission levels (add/delete/denied) in PHP constants before showing the bitMask() function you can use to check a user's permissions. They also include some simple pseudo-code to show how it's used. For more information, check out the complete article here.

tagged: bitmask unix permissions tutorial define constants bitmask unix permissions tutorial define constants

Link:


Trending Topics: