i have a script for replace char that i want for URI in php.
But now i need these result but using Javascript. i've try to change using Javascript but cant run

function seo_title($s) {
    $c = array (' ');
    $d = array ('-','/','\\',',','.','#',':',';','\'','"','[',']','{','}',')','(','|','`','~','!','@','%','$','^','&','*','=','?','+');

    $s = str_replace($d, '', $s); 

    $s = strtolower(str_replace($c, '-', $s)); 
    return $s;

Help me please

Recommended Answers

All 4 Replies

Member Avatar for iamthwee

example unclear

Try this..

function seo_title(cIncoming)
  var cNew = "";
  cNew = cIncoming.replace(/[!@#$%^&*()_+=,\.<>\/\\\[\]\{\}]/g , ""); //build a regex for unwanted chars add whatever else you need...
  cNew = cNew.replace(/ /g, "-");
  return cNew;

the above is not tested. The Regex is probably off due to escaping issues, but see what you get :-P

Member Avatar for diafol

There are many slugify scripts out there. Perhaps a Google trawl could help?

thanks ryantroop, it works !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.