• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you simplify this function?

#1
[eluser]codex[/eluser]
I have this function for normalizing tags before writing them to the database. It works, that's not the issue, but I was just wondering if it's possible to shorten or simplify the sucker.

If not clear, what it does is it strips characters like '[email protected]#$%^&*(' and replaces characters like 'éèëê' with e, 'ÀÁÂÃ' with A etc.

Code:
function normalize_tag($s) {
        
        $s = htmlentities($s);
        $s = str_replace('http://', '', $s); // Strip http://
        $s = preg_replace ('/&([a-zA-Z])(uml|acute|grave|circ|tilde|cedil|ring);/', '$1', $s); // Replace accented chars with regular chars
        $s = html_entity_decode($s);
        $s = preg_replace('/ +/', '_', $s); // Replace multiple spaces with underscore
        $s = preg_replace('/-+/', '_', $s); // Replace multiple divisions with underscore
        $s = preg_replace('/_+/', '_', $s); // Replace multiple underscores with just one
        $s = ereg_replace('[^A-Za-z0-9_-]', '', $s);
        $s = strtolower($s);
        
        return $s;
        
    }


Messages In This Thread
Can you simplify this function? - by El Forum - 05-17-2008, 08:03 AM
Can you simplify this function? - by El Forum - 05-17-2008, 08:56 AM
Can you simplify this function? - by El Forum - 05-17-2008, 09:18 AM
Can you simplify this function? - by El Forum - 05-17-2008, 05:59 PM
Can you simplify this function? - by El Forum - 05-18-2008, 12:06 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.