1

what is the best preg_replace to create an SEOed text to be used in uri ??

i mean like if we had this uri http://t.com/SOME RANDOM $#@ TEXT _ + ?/ =\ , what is best preg_replace expression to clean it up ?

Thank you .

EDIT : assuming you have multiple languages in the random text language ??

Rami Dabain
  • 4,709
  • 12
  • 62
  • 106
  • @BoltClock : yes , that is not a valid URI , lets assume that `SOME RANDOM $#@ TEXT _ + ?/ =\` is some entry from a database , and you want to use it in that position in that URI , how would you make it valid ? . – Rami Dabain Jan 17 '11 at 11:03
  • @Gumbo : hmmm , i think a valid string that is accepted in a URI as a single parameter – Rami Dabain Jan 17 '11 at 11:03

2 Answers2

1

I guess what you're looking for is URL sanitizing. Here's a link to a filter for php: http://php.net/manual/en/filter.filters.sanitize.php

kovshenin
  • 31,813
  • 4
  • 35
  • 46
1

Do you mean a slug?

Slug('SOME RANDOM $#@ TEXT _ + ?/ =\\'); // some-random-text

For that this should be enough:

function Slug($string, $slug = '-')
{
    return strtolower(trim(preg_replace('~[^0-9a-z]+~i', $slug, $string), $slug));
}
Alix Axel
  • 151,645
  • 95
  • 393
  • 500