0

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

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

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

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

Help me please

4
Contributors
4
Replies
20
Views
3 Years
Discussion Span
Last Post by Linddha
1

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

Edited by ryantroop

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.