So if you have a problem in making on the fly URL’s for your app, here is a small function for helping you with that.

function clean_url($str) {
	$clean = preg_replace("/[^a-zA-Z0-9/_|+ -]/", '', $str);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[/_|+ -]+/", '-', $clean);

	return $clean;
}

Here is a small demo:

thi$ i$ and URL made on the fly with șome șpecîal chars like % and # and @ that they don't need to apear ok?

will return:

thi-i-and-url-made-on-the-fly-with-ome-pecal-chars-like-and-and-that-they-dont-need-to-apear-ok

Like it?

If this has been useful you should give me a beer

Comment now!
















Trackbacks