FREE PHP Scripts and Snippets

Ready to use Free PHP scripts and snippets to use in your projects.
All Free Scripts & Snippets Complete PHP Scripts

Create URL Slug from text string [PHP]

>> Share on Facebook & Impress your friends <<

PHP Script to create URL from string. It retails only URL Safe characters in the strings. So, now easily create URL Slug from text string for your Search engine optimization needs.

<?php

/*
Name : PHP function to Create URL Slug from a text string

It is great tool for generating SEO URLs.
*/

function createUrlSlugFromString($string){
	
	// Remove spaces from front and end of the string
	$string = strtolower(trim($string));
	
	// Change all non-alphanumeric character sequences to -
	$string = preg_replace('/[^a-z0-9-]/', '-', $string);
	
	// Change multiple hyphens to single hyphens
	$urlSlug = preg_replace('/-+/', "-", $string);
	
	// Remove trailing - from the slug
	$urlSlug=trim($urlSlug,"-");
	
	// We are done! Now return the sluf back.
	return $urlSlug;
	
} // End of Create URL Slug from a text string function


// Calling the URL Slug creation function
echo createUrlSlugFromString ( " This is some text with     multiple spaces and punctionations (,.?)");

?>


Request Custom Snippet

Just $5 Onwards

 

Previously Ordered Snippets

PHP snippet to parse a text and remove all non alphanumeric characters from it.
Price $5 Order Now

I want a function to find number of occurrences of a word in a given text and then give their positions as comma separated list.
Price $5 Order Now

I want a function to validate a given and tell if it safe URL slug i.e. it should check that it does not have any special characters, spaces or any non-alphanumeric characters except hyphens
Price $5 Order Now

Random PHP Scripts and Snippets

Detect Valid Email address with PHP

A very simple php snippet to check if an email id is valid or not. If the email address is...

PHP extract multiple emails from text

PHP Script to scan a text and extract all email ids contained in the text. It outputs email addresses as...

PHP - Extract all links from a web page

PHP Script to extract all links from a web page. This PHP Snippet reads the contents of a web page...

Make URLs in plain text clickable [PHP]

This is a simple PHP function to parse text provided and automatically hyperlink the links in the text.

Extracting all numbers from a String [PHP]

This PHP function extracts all numbers from a String and prints them as a comma separated list of numbers. Ready...

[PHP] generate keywords from text function

This is a simple function written in PHP to generate keywords from any text. Just pass any free text to...

PHP Code to list all files in a folder

This PHP Code snippet lists all files in a folder and hyperlinks them accordingly. Very clean, easy to use function....

Free PHP folder to gallery script

100% Free PHP folder to gallery script. Just give the name of folder and it will generate gallery of all...