slugify a String In php

How to Make Friendly URL in PHP? How to Slugify a String in PHP?

What Is Friendly URL?

friendly URL is a Web address that is easy to read and includes words that describe the content of the webpage. Friendly URL Is Also Known As Slug URL. Creating Slug URL From String Is Known As Slugify. This type of URL can be “friendly” in two ways.

1) It can help visitors remember the Web address

2) it can help describe the page to search engines.

How To Create Friendly URL In PHP?

Creating Slug URL From String Is Known As Slugify.

How To Slugify a String In PHP?

Here is a snippet for generating a Friendly URL / Slug in PHP


function slugify($string){
        return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-'));


Here I have Created A Function To Which I will Pass a String And It will return me a Friendly URL / Slug.

You Can Use It in Your Code As:


<?php echo slugify('!hello Everyone!? how are you???'); ?>

The Output of the Above Code Will Be :


If You Have Any Problem Or Doubts, Please Do Ask Or Suggest In Comment.

Also Check Out :

Redirect HTTP To HTTPS Using htaccess File

Redirect HTTP To HTTPS Using htaccess File

If SSL is enabled for your entire site, you need to assure that every link pointing to your site’s HTTP version is redirected automatically to the HTTPS version. In order to Redirect Your HTTP site to HTTPS, you need to modify your .htaccess file These are the rules that You have to add to the
Read More »


React Native Material date picker component

React Native Material Date Picker Component Today I am Share a Material Date Picker Component for react-native. Which is very easy to use. Features Easy usage. Material design. Easy localizable. ScreenShot Installation And Usage Install Using NPM Or YARN. npm install –save react-native-material-date-picker or yarn add react-native-material-date-picker Usage import { ModalDatePicker } from “react-native-material-date-picker”; const
Read More »

1 comment

Follow Us On Social Media:

About: Aakash Kothari

I am passionate about my work. Because I love what I do, I have a steady source of motivation that drives me to do my best. In my last job, this passion led me to challenge myself daily and learn new skills that helped me to do better work

One thought on “How to Make Friendly URL in PHP? How to Slugify a String in PHP?”

Leave a Reply

%d bloggers like this: