add special characters to DB?

Discussion in 'PHP' started by arale, Jul 7, 2009.

  1. #1
    Hello,

    I have a question about preg_match, I couldn’t understand how it works. Code below allow me to add word without space and special characters. I want to add words for another language, which contains spaces and special character like (â, ế, đ…) but not (?, #, %...etc). So my questions are:

    1. I set DB to utf8_general_ci, is it correct? To show special unicode characters

    2. How to modifly code below to make it adds words with space and special unicode characters? I think it is about preg_match, but I don’t know how it works ??? :confused:

    
    function add_new_word($word){
    	if (preg_match('/^[a-zA-Z]+$/', $_POST['word'])) {
    		$word = $_POST['word'];
    	} else {
    		echo 'Illegal parameters!';
    		exit();
    	}
    
    	if (add_word($word)) {
    		echo "<p>Successfully added word! </p>";
    	} else {
    		echo "<p>Failure! Unable to add word! </p>";
    	}
    	echo "<b>Word:</b> $word<br/>";
    }
    
    PHP:
    Thank you
     
    arale, Jul 7, 2009 IP