A good example of this is matching parameters in URLs. You can give the variables in your URL a name making your code a bit more readable. In the URL
1 | /category/1/post/5 |
we want to get the category id and the post id. A simple match would be to simply match the digits.
1 | ^\\/category\\/(\\d+)\\/post\\/(\\d+)$ |
This would then give you code something like:
1
2
3
4
5
6 $input_line = '/category/1/post/5'
preg_match('/^\\/category\\/(\\d+)\\/post\\/(\\d+)$/', $input_line, $output_array);
if ($output_array[1] === 1 && $output_array[2] === 5) {
// Do some magic
}
We can give our matches a name by adding a
1 | ?<name> |
to your pattern. So your new pattern will look like:
1 ^\\/category\\/(?<category_id>\\d+)\\/post\\/(?<post_id>\\d+)$
Now we can refactor our code to make it that bit more readable:
1
2
3
4
5
6 $input_line = '/category/1/post/5'
preg_match('^\\/category\\/(?<category_id>\\d+)\\/post\\/(?<post_id>\\d+)$', $input_line, $output_array);
if ($output_array['category_id'] === 1 && $output_array['post_id'] === 5) {
// Do some magic
}
Links to php live regex
More reads
The Invisible Design Paradox: Why Beautiful Websites Don’t Always Succeed
There’s a persistent myth in digital strategy that equates aesthetic appeal with business success. The thinking goes that a beautiful website naturally translates into a successful one. The reality, however, is more nuanced.
Q3 Project updates
As a small yet busy web agency we often have little time to shout about what we are up to, and also work on secret projects we are unable to tell you about. Here’s a snapshot of what we’ve been working on…
[updated] Diagrams to live your life by
As part of our Practically Academy Sam shared a whole series of diagrams that help in the strategy work that he does, and beyond.



![[updated] Diagrams to live your life by](https://b2209735.smushcdn.com/2209735/wp-content/uploads/DiagramsTLYLB-Choice-vs-happiness-paradox-400x250.jpg?lossy=2&strip=1&webp=1)