0

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>
3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by ivan3510
0

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

Edited by ivan3510: n/a

0

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.

0

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

0

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
}

Edited by ivan3510: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.