Welcome Guest, Not a member yet? Register   Sign In
Cleaning Word formatting
#1

[eluser]Dan Bowling[/eluser]
I need to clean up stuff pasted from Microsoft Word, so I figured a library would be a good way to go. What I wrote seems to work, but the way I'm doing it just doesn't feel right. Anyone have any suggestions?

The Library
Code:
class Word {

    function clean($str)
    {
    if ($str==='') return $str;
    
    $patterns = array('/’/','/“/','/”/','/—/', '/•/');
    $replacements = array('\'','"','"','--','-');
    
    return preg_replace($patterns, $replacements, $str);
    }
}


A model using it
Code:
function update($column, $value, $id)
    {
        $this->db->where('region_id', $id);
        $data = array(
            $column => $this->word->clean($value)
        );
        $this->db->update('regions', $data);
    }

I'm specifically worried about cleaning character encoding up before I submit it to the database. Can I really just paste in the bad stuff to my php and use it in my replacement function like I did?




Theme © iAndrew 2016 - Forum software by © MyBB