Character Filter System Like Wordpress Title Filter

Discussion in 'PHP' started by SNaRe, Dec 6, 2007.

  1. #1
    For example when we enter weird characters to wordpress title it converts them so something else.It clears it .
    Is there a function like that to clear this characters?
     
    SNaRe, Dec 6, 2007 IP
  2. dzysyak

    dzysyak Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Probably something like that should work
    preg_replace("(\W)", '_', $str)
     
    dzysyak, Dec 6, 2007 IP
  3. SNaRe

    SNaRe Well-Known Member

    Messages:
    1,132
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    165
    #3
    what is this mean "\W"?
     
    SNaRe, Dec 6, 2007 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You could always take a look into wordpress source code and see exactly what it does :)
     
    hogan_h, Dec 6, 2007 IP
  5. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't know if it emulates the wordpress url but to do automated posting to my wordpress databases I just use ..

    
    $p_title = str_replace(" ","-",strtolower($p_title)) ;
    $p_title = ereg_replace("[^A-Za-z0-9\-]", "", $p_title );
    $p_title = str_replace("---","-",$p_title) ;
    
    PHP:
    then I force that as the 'guid' entry to the db.

    The code above switches out spaces " " with dashes "-" then removes any character that's not alphanumeric or a dash. After that I switch "---" out with "-" ... the "---" would occur if the string " - " occurs in the title of something quite frequently.

    Yes it's a poorboy hack but it works like a charm, hope it helps.
     
    ErectADirectory, Dec 6, 2007 IP