Hi!
This is my problem. If I write letter č or ć in textarea, and then if I use php to check if there in textarea is letter č or ć, it doesn't work, here's code:

<?php
if($_POST['sub']){
	$tekst=$_POST['tekst'];
	$array=array("&#x010D"); //& # x 010D iz unicode for č, i also tried ascii, and I also tried č
	if(in_array($tekst,$array)){
		echo "ok";
	}
	$var="&#x010D";
	if($tekst==$var) echo "yes";
}
?>
<form method="post" action="">
	<textarea name="tekst"></textarea>
	<input type="submit" name="sub">
</form>

Well, get_html_translation_table(HTML_ENTITIES) doesn't work, I used their example, but nothing, I'm getting è (& egrave) when I use this:

$str="č";
$en=strtr($str,get_html_translation_table(HTML_ENTITIES));
echo $en;

and Ä (& Auml) when I'm using this:

if($_POST['sub']){
	$str=$_POST['tekst'];
	$en=strtr($str,get_html_translation_table(HTML_ENTITIES));
	echo $en;
}

htmlspecialchars works, but it writes č (in source code of page), not & # 269;, so it doesn't work

PHP is notoriously bad with UTF-8 characters. The only reasonable way I think you would accomplish this would be using the multi-byte functions. http://www.php.net/manual/en/ref.mbstring.php

$str = č;
if( mb_strpos( $_POST['tekst'], $str ) !== FALSE ) {
  echo 'Found String';
} else {
  echo 'No String';
}

I haven't tested this, but it should handle multi-byte characters better than the standard functions, however you don't have anywhere near the variety of functions to work with.

No, it doesn't work. (No string)

It shoud be the same way as the google translation, if they're using textbox.

And finally, I found a solution on php.net page, ord function. So, here it is:

function ascii($text){
	for($i=0;$i<mb_strlen($text,'UTF-8');$i++){
		$c=mb_substr($text,$i,1,'UTF-8');
	}
	$code="";
	for($i=0;$i<strlen($text);$i++){
		$c=substr($text,$i,1);
		$code.=$c;
	}
	return $code;
}
if($_POST['sub']){
	$tekst=ascii($_POST['tekst']);
	$tekst2="&# 269;";
	if($tekst2==$tekst) echo "yes"; //output is yes, so it works
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.