Member Avatar for Linddha

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

Member Avatar for iamthwee

example unclear

Member Avatar for ryantroop

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?

Member Avatar for Linddha

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.