Reader
  • Home
  • About
  • Deals
  • Services
  • Contact
You are here: Home / Archives for SEO

Format text into a SEO Friendly String

Last updated on October 1st, 2012 by Gabriel Livan

Hi,

This function takes a regular phrase and formats it into a seo friendly string which can be part of an URL.

<?php
function friendly_seo_string($string, $separator = '-')
{
$string = trim($string);

$string = strtolower($string); // convert to lowercase text

// Recommendation URL: http://www.webcheatsheet.com/php/regular_expressions.php

// Only space, letters, numbers and underscore are allowed

$string = trim(ereg_replace("[^ A-Za-z0-9_]", " ", $string));

/*

"t" (ASCII 9 (0x09)), a tab. 
"n" (ASCII 10 (0x0A)), a new line (line feed). 
"r" (ASCII 13 (0x0D)), a carriage return. 

*/

$string = ereg_replace("[ tnr]+", "-", $string);

$string = str_replace(" ", $separator, $string);

$string = ereg_replace("[ -]+", "-", $string);

return $string;
}

$str = friendly_seo_string('Lorem Ipsum is simply dummy text.');

// Outputs: lorem-ipsum-is-simply-dummy-text
echo $str;
?>

This string can be added to a friendly URL like this:
http://www.yourdomain.com/info/lorem-ipsum-is-simply-dummy-text.html

Recommendation URLs:
http://www.webcheatsheet.com/php/regular_expressions.php
http://www.php.net/manual/function.ereg-replace.php

Filed Under: PHP, SEO

« Previous Page

About Me

Gabriel LivanHey, there! I'm Gabriel Livan, Web Developer, Blogger and Internet Marketer. I love making fast, secure and scalable web applications, running and travelling around the world. I blog about WordPress, site speed & security and quality tools for web professionals. Read more

What are you looking for?

Categories

  • AJAX (22)
  • Deals (10)
  • Design (30)
  • eBooks (2)
  • Flash (19)
  • Freebies (11)
  • General (62)
  • Giveaways (1)
  • Graphics (27)
  • HTML & CSS (35)
    • Frameworks (9)
  • JavaScript (160)
    • Frameworks (8)
    • jQuery (89)
    • MooTools (14)
  • Page Loading Speed (2)
  • Photoshop (3)
  • PHP (113)
  • Reviews (8)
  • SEO (6)
  • Statistics (2)
  • Web Tools (13)
  • WordPress (27)
    • Plugins (15)
    • Snippets (4)
    • Tools (2)
    • Tutorials (6)

Copyright © 2026 · BitRepository.com - All Rights Reserved

  • Home
  • About
  • Contact