News Feed
Sections




News Archive
feed this:

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

Lukas Smith's Blog:
Query parameter handling in Symfony2
May 14, 2012 @ 11:56:37

Lukas Smith is looking for feedback about a question that's been in his mind a lot lately - can the handling of query parameters be made better for the Symfony2 framework (and even easier to use).

Obviously you can already access query parameters today already but it could be easier. Essentially what I want is a way for developers to easily configure what query parameters they expect and what values they expect. This is useful for several things like easier reading and validating of query parameters, self documenting API both for API docs for humans but also for machines.

He's asking for feedback and ideas from the community on a proposed solution that could make things more flexible. He also briefly mentions the route matching and how qurey parameters could cause them not to match:

For one I don't think that a mismatch on a route requirement of a query parameter cause the route to not match. However then it can quickly become confusing for the end user or it would require adding more and more syntax to handle all the different cases.
0 comments voice your opinion now!
symfony2 query parameter handling solution routing match


PHPMaster.com:
Regular Expressions
September 27, 2011 @ 09:42:28

Regular expressions have always been something that have mystified developers, even those seasoned ones looking to match the most complicated data. If you're just venturing into the world of regex, PHPMaster.com has a good guide to help you wade through some of the basics.

It makes all the sense of ancient Egyptian hieroglyphics to you, although those little pictures at least look like they have meaning. But this… this looks like gibberish. What does it mean? [...] When you're looking to go beyond straight text matches, like finding "stud" in "Mustard" (which would fail btw), and you need a way to "explain" what you're looking for because each instance may be different, you've come to need Regular Expressions, affectionately called regex.

The include a (somewhat) complicated example regex string and break it down chunk by chunk - groupings, character sets, multiple matching, delimiters and more (the pattern matches valid email addresses). They show how to use it in PHP with preg_match, preg_replace and preg_match_all for different situations.

0 comments voice your opinion now!
regular expression introduction email match tutorial


Stoimen Popov's Blog:
preg_match Give Names to the Matches
July 06, 2010 @ 11:01:48

In a quick post to hos blog today Stoimen Popov points out a handy feature of the preg_match function in PHP (in PHP 5.2.2 and higher) to be able to name the results of the regular expression match.

In PHP 5.2.2+ you can name the sub patterns returned from preg_match with a specific syntax. [...] This is extremely helpful, when dealing with long patterns. [...] Although it may look difficult to maintain, now you can simply name the sub patterns of preg_match and to call them with their associative array keys. This is more clear when writing code and it's definitely more maintainable.

The key is to use a special syntax as a part of the expression's pattern. This replaces the numeric keys of the matches with values you define, making it simpler to use the results (instead of having to work with numbers that don't match much of anything). Code and expression examples are included.

0 comments voice your opinion now!
named result match pregmatch regularexpression


Jordi Boggiano's Blog:
Major glob() fail
December 07, 2009 @ 13:50:54

Jordi Boggiano had the "pleasure" of discovering a small quirk with PHP's glob function in an application he was working on - watch out for directories that contain square braces, they won't return in the results!

Working on some personal project that lists a bunch of stuff on my hard drive, I found out that directories that contain square brackets (those []) don't return any results for the simple reason that glob reads [stuff] as a character class, just like in regular expressions. When you know it it makes perfect sense, but when you don't, the documentation is really not so helpful. Of course it mentions libc's glob() and unix shells, but not everyone knows what that implies at first glance.

He tried a few things to get around the bug (including escaping the brackets in the directories) but ended up writing a function (glob_quote) to handle the escaping of all of the meta-characters glob might need to escape to return all of the files and folders correctly.

1 comment voice your opinion now!
glob fail regularexpression match


Echolibre Blog:
Customising Zend Framework Routing
March 13, 2009 @ 10:23:04

On the echolibre blog J.D. has made a new post looking at Zend Framework routing and how you can customize it to get the user where they need to go.

I wanted to write a post that shows a few different ways to customise Zend Frameworks routing when you're using their MVC implementation. Most of this is covered in the documentation, but it can be a little difficult to dig out.

He starts with the normal routing setup (the standard /module/controller/action and /controller/action setups) and moves on to the "magic" - a way to have a standard "framework URL" without having to include an action. He sets up a route with a wildcard to catch anything for that controller and passes it off to a custom router that goes through the request values and returns the values as though they were formatted normally in the URL.

0 comments voice your opinion now!
zendframework routing custom wildcard match parameter url


Gareth Heyes' Blog:
Regular expression challenge
October 19, 2007 @ 14:48:00

Gareth Heyes has posted another challenge to his blog - this time it involves using a regular expression to convert the inputted string into the output he's given.

After the success of my "a bit of fun" challenge, a few people asked for some more challenges. So I was answering a question on a mailing list that I'm a member of and I thought it would be a good topic for a little challenge and help sharpen everyone's regular expression skills.

This time, his challenge involves taking the input, rail start/end locations from an array and, via the PHP script given (no regular expression in it, of course) make the output, a sort of JSON formatted message. It's already been answered, but if you want to, try it yourself first then read the answer below the post.

1 comment voice your opinion now!
regular expression challenge input output match regular expression challenge input output match


PHP Security Blog:
Holes in most preg_match() filters
April 04, 2007 @ 07:15:50

On the PHP Security Log today, Stefan Esser points out some holes in most of the filters using preg_match that he's seen in examples and the like all around the web. Some of these things could cause issues that could breach the security of your application.

During the last week I was performing some audits and like so often it contained preg_match() filters that were not correct. Most PHP developers use ^ and $ within their regular expressions without actually reading the documentation about what they really achieve.

However the problem is, that the author of such a regular expression did not correctly read the documentation and mistakes the $ character for the definitive end of the subject.

According to Stefan, the actual documentation for the $ character in a regular expression isn't quite used that way. It does mean "the end" of the match but it can also match against a newline as well. His suggestions? Use the /D modifier on the end of the expression to match the real "the end" and not how it might match otherwise.

0 comments voice your opinion now!
security pregmatch filter match endofline clean security pregmatch filter match endofline clean


roScripts.com:
PHP search engine
March 30, 2007 @ 09:55:00

The roScripts website has a new tutorial that anyone just starting out to create a search engine with PHP and MySQL should get their hands...er eyes on. It steps through the creation of a simple PHP-based search engine, showing multiple methods to achieve the goal.

The right search engine on your website won't bring you more traffic but it will help your visitors to better locate things so it will keep them on your pages. A good search engine implemented can increase your hits with almost 30% and this is tested. I'm not talking just to have a tutorial.

The different methods the show how to implement include:

  • using a straight LIKE on each word entered
  • paring down those results using ORs on other columns too
  • implementing the Porter Stemmer algorithm
  • finding matches that contain the term but not only one part of it
  • Full-text searches

It's a good overview of some of the basic steps to getting your own search up and running, but some of them, when applied to sites with larger amounts of data behind them, wouldn't be useful at all (slowness mainly).

0 comments voice your opinion now!
searchengine like fulltext match porterstemmer searchengine like fulltext match porterstemmer


Evolt.org:
Working With Fractions In CSS and PHP
February 12, 2007 @ 09:03:00

Evolt.org has an interesting new article posted today about combining CSS and PHP to display fractions correctly on your pages.

Most of us are uncomfortable with using fractions when writing programs. If we encounter a fraction, we will first convert it into a floating point number (with decimals) and proceed from there. Most programming languages would prefer to use 0.5 as opposed to 1/2 because the later might conflict with the syntax of the languages. In this article, I will discuss my attempt to work with fractions in one of the PHP projects that I have done.

They start with the CSS to handle the output before moving into the PHP code. The code given will take in a decimal number and do its best to match it up with a fraction string value out of an array. The result is the echoed out with sup and sub tags to create the correct effect.

0 comments voice your opinion now!
fractions css sup sub html tutorial match array fractions css sup sub html tutorial match array


Tiffany Brown's Blog:
A better RegEx pattern for matching e-mail addresses
December 13, 2006 @ 08:15:00

Though not specifically related to PHP, I wanted to share a helpful tip that Tiffany Brown has posted to her blog today - a nice, compact regular expression to handle the matching of email addresses.

A few weeks ago, I posted a regular expression pattern < href="http://tiffanybbrown.com/2006/11/09/a-pattern-for-matching-e-mail-addresses/">for matching e-mail addresses. Below is a more refined version:

^[-+.w]{1,64}@[-.w]{1,64}.[-.w]{2,6}$

Not only does it match the traditional email address formats, but it also will match addresses with periods in the name, British domains, and new TLDs like '.travel' or '.museum'.

0 comments voice your opinion now!
regular expression match email address refined regular expression match email address refined



Community Events





Don't see your event here?
Let us know!


opinion update voicesoftheelephpant symfony community install version security series introduction release package composer podcast application laravel library framework language interview

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework