Sunday, August 23, 2020

How to Slugify a String in PHP

How to Slugify a String in PHP

🔥 Save unlimited web pages along with a full PDF snapshot of each page.
Unlock Premium →

Here is a snippet for generating a URL friendly slug in PHP

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

And you can use it in your code like so

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

Source: http://www.seanbehan.com/how-to-slugify-a-string-in-php/
This web page was saved on Saturday, Aug 22 2020.

Upgrade to Premium Plan

✔ Save unlimited bookmarks.

✔ Get a complete PDF copy of each web page

✔ Save PDFs, DOCX files, images and Excel sheets as email attachments.

✔ Get priority support and access to latest features.

Upgrade now →

No comments: