I came across this nicely designed audio player on CodePen, put together by Michael Zhigulin It uses the waves.js click effect library...
Create a URL from a string of text with PHP and mod_rewrite
A PHP function to generate URL slugs
Quite often when developing big web apps you may need to use mod_rewrite to generate SEO friendly URLs from a string of text, Very similar to the way WordPress generates URLs for blog posts.
The Code
Below is the function which will remove all the spaces and special characters from a string and convert it to lowercase making sure it’s formatted ready to be used as a URL.
function create_slug($string == null){
// if no string
if($string == null){
return false;
}
$string = preg_replace( '/[«»""!?,[email protected]£$%^&*{};:()]+/', '', $string );
$string = strtolower($string);
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
return $slug;
}
echo create_slug('This is my page title');
// this should print out: this-is-my-page-title
The .htaccess
If you were to use the function above in conjunction with generating page urls as part of a web application you’ll need some way of the server handling url redirects etc. The easiest way to do this is by using .htaccess. More information can be found about .htaccess here. What the code below does is, it takes the url for example ‘http://papermashup.com/this-is-my-page-title’ then appends the; ‘this-is-my-page-title’ as a GET variable value, in the case below we’re saving it in the GET variable ‘slug’ which is appended to index.php. So now when we visit ‘http://papermashup.com/this-is-my-page-title’ the server looks for http://papermashup.com/index.php?slug=this-is-my-page-title. Then it’s up to you to process the data for each url. So if you had a web app you might have a MySQL database that holds all your site URLs and data which you search based on the page slug.
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?slug=$1 [QSA]
Nice post,Thank you.
Great tips URL creating so helpful information thanks for sharing
Nice! You can use [^A-z0-9-] ER.
@DaveBowman: that stands for “Query String Append”, which means it mingles in additional GET parameters with the rest of the things you pass from the htaccess.
it’s working
Nice tip, but what’s the [QSA] directive at the end of the rewrite rule?