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

PHP Create thumbnail of an image

PHP Script to create thumbnail of any image (.jpg, .png and .gif). This create thumbnail function is ready to use....

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....

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...

Create URL Slug from text string [PHP]

PHP Script to create URL from string. It retails only URL Safe characters in the strings. So, now easily create...

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.

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...

Generate Random Password in PHP

PHP Script to Generate Random Password. You can set the list of characters that you want to be used in...

[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...