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 :

hello-everyone-how-are-you

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

Also Check Out :

Creating & Configure DevExtreme Application In React Js

Creating & Configure DevExtreme Application In React Js

Creating & Configure DevExtreme Application If You Are Creating Project From Start You Can install React Template Using DevExtreme CLI: npx -p devextreme-cli devextreme new react-app app-name cd app-name npm run start To switch to another layout, open the src\Content.jsfile and replace the SideNavOuterToolbarimport with SideNavInnerToolbar: import { SideNavInnerToolbar as SideNavBarLayout, SingleCard } from ‘./layouts’;
Read More »

0 comments
A React Native component to view a modal on iOS Device

A React Native component to view a modal on iOS Device

react-native-ios-modal Intro: A React Native component to display a modal on an iOS device  by natively wrapping and presenting a React Native view within a UIViewController. Since this is just using a UIViewController, this component also supports setting the UIModalPresentationStyle and UIModalTransitionStyle. Supports setting isModalInPresentation and separately disabling the native swipe down gesture when the modal is using pageSheet modalPresentationStyle. You can use ModalView anywhere in your app and present a view modally either programmatically via a
Read More »

0 comments

Follow Us On Social Media:

Facebook.com

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: