0

I am retrieving a data from data base in that some of the array contains a result like this.

playa|beach|mar|isco

When the user types e or é.I want to display only "beach".If the user types i or í i want to display only "isco". I am using this code:

$indx=0;
while($row = mysql_fetch_array($rc)){

    if (strpos($row['texto'],'|') !== false) {

        $pieces = explode("|", $row['texto']);
        foreach($pieces as $key => $one) {
           if(strpos($one, $fincas) !== false)
               $indx=$key;
        }
        $row['texto'] = $pieces[$indx];
    }
}

When the user types "e" its displaying properly "beach" but when the user types "é" its displaying "playa".

In php i have to display an array which contains e or é(i or í)

M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
user3350169
  • 209
  • 1
  • 4
  • 14
  • 3
    You would need to first normalize your string either using `iconv` or `Normalizer::normalize` (PHP 5.3) – See the question [Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string](http://stackoverflow.com/q/158241/112968) – knittl Oct 14 '14 at 05:46

1 Answers1

1

First of all, you need to make sure you're getting the POST in a standard format.

Ensure:

  • in HTTP Header: Content-Type:text/html; charset=UTF-8
  • in HTML Head:
  • in the form tag:

Then, before starting your loop, translate $fincas into "normalized" ascii:

iconv("utf-8","ascii//TRANSLIT",$fincas);

That should do it.

Shadow Radiance
  • 1,349
  • 13
  • 20