Asked  7 Months ago    Answers:  5   Viewed   37 times

I am using the stripos function to check if a string is located inside another string, ignoring any cases.

Here is the problem:

stripos("ø", "Ø")

returns false. While

stripos("Ø", "Ø")

returns true.

As you might see, it looks like the function does NOT do a case-insensitive search in this case.

The function has the same problems with characters like Ææ and Åå. These are Danish characters.

 Answers

56

Use mb_stripos() instead. It's character set aware and will handle multi-byte character sets. stripos() is a holdover from the good old days when there was only ASCII and all chars were only 1 byte.

Wednesday, March 31, 2021
 
Uours
answered 7 Months ago
65

Looks like you are attempting to run multiple statements, possibly through a mysql_query() or mysqli->query() which only support single statements. Instead you need to execute this with mysqli->multi_query() or mysql_multi_query().

Saturday, May 29, 2021
 
gMale
answered 5 Months ago
53

There are reserved characters, that have a reserved meanings, those are delimiters — :/?#[]@ — and subdelimiters — !$&'()*+,;=

There is also a set of characters called unreserved characters — alphanumerics and -._~ — which are not to be encoded.

That means, that anything that doesn't belong to unreserved characters set is supposed to be %-encoded, when they do not have special meaning (e.g. when passed as a part of GET parameter).

See also RFC3986: Uniform Resource Identifier (URI): Generic Syntax

Tuesday, June 8, 2021
 
Dail
answered 5 Months ago
75

You can use preg_grep function of php. It's supported in PHP >= 4.0.5.

$array = array(0 => 'blue', 1 => 'red', 2 => 'green string', 3 => 'red');
$m_array = preg_grep('/^greens.*/', $array);

$m_array contains matched elements of array.

Tuesday, August 3, 2021
 
aWebDeveloper
answered 3 Months ago
94

Try this out: :-D

function check_array($array, $string){
   $trans = array("é" => "e", "é" => "e", "á" => "a", "á" => "a", "í" => "i","í"=>"i", "ó"=>"o", "ó" => "o", "ú" => "u", "ú"=>"u","ö" => "u", "ü"=>"u");
   $realString = strtr($string,$trans);
   foreach($array as $val){
      $realVal = strtr($val,$trans);
      if(strcasecmp( $realVal, $realString ) == 0){
         return true;
      }
   }
   return false;
}

so to use it:

check_array($array, 'Camion');

using strcasecmp as per Felix Kling suggestion

Tuesday, August 24, 2021
 
Ramacciotti
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :