1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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