Tejas Rana
  • Home
  • About
  • Experience
  • Skills
  • Blogs
  • Technology
  • Contact
June 10 2015

SEO friendly URL generator

tejas Infi MVC, PHP

Hi, here is a function which I create for generating SEO friendly URL.
first we have to create a function called “friendlyURL”.
here is a code

<?php
function friendlyURL($inputString){
$url = strtolower($inputString);
$patterns = $replacements = array();
$patterns[0] = '/(&amp;|&)/i';
$replacements[0] = '-and-';
$patterns[1] = '/[^a-zA-Z01-9]/i';
$replacements[1] = '-';
$patterns[2] = '/(-+)/i';
$replacements[2] = '-';
$patterns[3] = '/(-$|^-)/i';
$replacements[3] = '';
$url = preg_replace($patterns, $replacements, $url);
return $url;
}
?>

 
Now this function will convert string into a SEO friendly URL.
How to use it?

<?php
echo friendlyURL('hi this is a seo friendly url & it convert/replace special characters.');
?>

 

Show limited words in PHP from string with HTML tags

Related Posts

CakePHP, PHP

The Most Common Mistakes CakePHP Developers Make : A Tutorial for Beginners

PHP

Data Encoding: A Guide to UTF-8 for PHP and MySQL

PHP

Building REST API for Legacy PHP Projects

Categories

  • .NET
  • Android
  • Angular
  • CakePHP
  • CSS
  • Devops
  • Drupal
  • Infi MVC
  • iOS
  • Javascript
  • Magento
  • Meteor
  • MongoDB
  • Opencart
  • Other
  • PHP
  • Python
  • Ruby
  • Tips & Tricks
  • WordPress

Recent Posts

  • Simplify Product Filtering by Category and Store ID in the Admin Panel with Our Powerful OpenCart 3.x Free Extension
  • Opencart 3.x Set currency based on user’s IP [Free Extension]
  • Anatomy of A Coronavirus-Proof Business[Infographic]
  • Opencart 3 Social Login Extension [FREE]
  • What is NGRX and Use of NGRX

Recent Comments

  • Nilesh on What is State Management in Angular? How to improve Performance?
  • Dinesh on Use Magento If You're Serious About eCommerce
  • Virendra on Use Magento If You're Serious About eCommerce
  • Tejas Rana on Show limited words in PHP from string with HTML tags
  • nadim on Show limited words in PHP from string with HTML tags
Tejas Rana
© Tejas Rana 2025