slugify a String In php
0 0
Read Time:1 Minute, 6 Second

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 :

hello-everyone-how-are-you

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

Also Check Out :

Artificial Intelligence Future: Transforming Industries and Society

Artificial Intelligence Future: Transforming Industries and Society

The future often arrives on the wings of new technologies, and Artificial Intelligence (AI) is the vanguard. As AI continues to advance, it’s set to revolutionize virtually every sector of our lives, from how we work and learn to how we manage our health and interact with the digital world. Here, we explore the transformative […]

0 comments
React Native Firebase Integration: A Comprehensive Guide

React Native Firebase Integration: A Comprehensive Guide

React Native Firebase Integration offers a seamless blend of React Native’s user interface capabilities with Firebase’s robust backend services, forming a dynamic duo for mobile app development. This guide dives deep into common challenges developers face when merging React Native with Firebase and provides targeted solutions to streamline the integration process. By focusing on React […]

0 comments

Follow Us On Social Media:

Facebook.com

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

By Akash 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

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

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

Leave a Reply

Discover more from TechDevil

Subscribe now to keep reading and get access to the full archive.

Continue reading