AndyPSV Posted December 12, 2011 Share Posted December 12, 2011 I've got already one that does it, but it stops after "=" sign. How to deal with it (that the function would not stop?) function _url($name) { # parse url $sign = '-'; $name = str_replace('"','',$name); $name = preg_replace("/[^a-zA-Z0-9\s]/","",$name); $name = str_replace(' ',$sign,$name); $name = str_replace($sign.$sign,$sign,$name); $name = str_replace($sign.$sign.$sign,$sign,$name); $name = str_replace($sign.$sign.$sign,$sign.$sign,$name); return $name; } Quote Link to comment https://forums.phpfreaks.com/topic/253012-preg_match-that-removes-all-the-special-chars-non-url-ones/ Share on other sites More sharing options...
AndyPSV Posted December 12, 2011 Author Share Posted December 12, 2011 found that, the problem wasn't in this; it was somewhere else Quote Link to comment https://forums.phpfreaks.com/topic/253012-preg_match-that-removes-all-the-special-chars-non-url-ones/#findComment-1297187 Share on other sites More sharing options...
AndyPSV Posted December 12, 2011 Author Share Posted December 12, 2011 function _url($name,$lenght='') { /* parse URL */ if(strlen($name) > $lenght) { $name = substr($name,0,$titleLenght); $tiny = 1; } $sign = '-'; $name = unhtmlspecialchars($name); $name = str_replace('-',' ',$name); $name = preg_replace("/[^a-zA-Z0-9\s]/","",$name); $name = str_replace(' ',$sign,$name); $name = str_replace($sign.$sign,$sign,$name); $name = str_replace($sign.$sign.$sign,$sign,$name); $name = str_replace($sign.$sign.$sign,$sign,$name); $name = str_replace($sign.$sign.$sign.$sign,$sign,$name); if($tiny == 1) { if(strpos($name,'-') !== false) $name = substr($name,0,strrpos($name,'-')); if(substr($name,-1) == $sign) $name = substr($name,0,-1); } if(substr($name,-1) == '-') $name = substr($name,0,-1); if(substr($name,-1) == '-') $name = substr($name,0,-1); if(substr($name,-1) == '-') $name = substr($name,0,-1); if(substr($name,-1) == '-') $name = substr($name,0,-1); return $name; } Quote Link to comment https://forums.phpfreaks.com/topic/253012-preg_match-that-removes-all-the-special-chars-non-url-ones/#findComment-1297200 Share on other sites More sharing options...
AndyPSV Posted December 12, 2011 Author Share Posted December 12, 2011 fixed. think that final; put it, because it might be useful for somebody. function _url($name,$lenght='') { /* parse URL */ if(strlen($name) > $lenght) { $name = substr($name,0,$lenght); $tiny = 1; } $sign = '-'; $name = unhtmlspecialchars($name); $name = str_replace('-',' ',$name); $name = preg_replace("/[^a-zA-Z0-9\s]/","",$name); $name = str_replace(' ',$sign,$name); for($i = 0; $i <= 10; $i++) $name = str_replace($sign.$sign,$sign,$name); if($tiny == 1) { if(strpos($name,'-') !== false) $name = substr($name,0,strrpos($name,'-')); if(substr($name,-1) == $sign) $name = substr($name,0,-1); } for($i = 0; $i <= 10; $i++) if(substr($name,-1) == '-') $name = substr($name,0,-1); return $name; } Quote Link to comment https://forums.phpfreaks.com/topic/253012-preg_match-that-removes-all-the-special-chars-non-url-ones/#findComment-1297214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.