Parsing URL Parameters with Swift
Here is an extension you can use in your Swift (v4) projects that makes it easy to parse parameters from a url. Given a url like, "http://example.com/?x=1&y=2", you can extract the x and y parameters into a key, value data structure. Here is the s...
Written by Sean Behan on 09/23/2018
How to Parse Query Strings in PHP
Here is a quick snippet for parsing query strings in PHP. You can use the `parse_url` and `parse_str` methods. `parse_str` will create a variable for you populated with results. $url = "http://www.seanbehan.com/path/?param=key"; parse_str(parse_url...
Written by Sean Behan on 12/04/2017
How to Slugify a String in PHP
Here is a snippet for generating a URL friendly slug in PHP function slugify($string){ return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-')); } And you can use it in your code like so ...
Written by Sean Behan on 10/26/2017
Apache Rewrite Rule for Mapping to index.php in Sub Folders
Below is an example URL structure with rewrite rules using an Apache .htaccess file. GET /a/ => a/index.php GET /a/b/ => a/b/index.php GET /a/b/c/ => a/b/index.php This URL mapping will give you pretty URLs in PHP without needing t...
Written by Sean Behan on 10/20/2017
Extract Domain Names From Links in Text with Postgres and a Single SQL Query
This query and pattern will return urls in text all within a single SQL query. select substring(column_name from '.*://([^/]*)') as domain_name from table_name; And here it is in a larger query, say for retrieving page view counts for referrers. ...
Written by Sean Behan on 11/23/2013
Scope Routes/URLs By Username (like Twitter) in Your Rails Application
There are a few things that need to be taken care of before you can get this to work. The first thing (although, any of the following steps can be done in any order) to take care of involves your User model. You need to override the to_param method, so th...
Written by Sean Behan on 06/17/2012
How to Use Pretty URLs with Rails will_paginate Plugin
The will_paginate plugin for Rails uses a key/value assignment like ?page=2, rather than the pretty url formats such as /page/2 ... This is because url generation and mapping are handled by the routes.rb file. You'll need to modify the file so that rails ...
Written by Sean Behan on 06/17/2012