How To Create URL Slug from Post Title in PHP


0

In this tutorial we will discuss how to create url slug from post title in php

Php Regular expression function that will check and replaces spaces between words with hyphens.

<?php
function create_slug($string){
   $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
   return $slug;
}
echo create_slug('does this thing work or not');
//returns 'does-this-thing-work-or-not'
?>

Also Read: Email Address Validation using php


Like it? Share with your friends!

0
Developer

0 Comments