-1

I am trying to compare two string but it always return false . Both strings are same but when I checked it further got to know that one is in utf-8 ( coming from database/eloquent ) and other being submitted from form ( ancii ) . Main issue is that in databse there are spaces between and after string . I also tried to use mysql TRIM() but failed . Any lead what should I do ?

I also tried to change encoding with

iconv("UTF-8", "ISO-8859-1",str_replace(' ', '', $request->sentence))

Tried comparing string with strcmp() but it never returns 0

Any help is appreciated and thanks for paying attention .

 $sentence = AvailableSentence::
    where('sentence_id', $request->sentence_id)
    ->with(['details'])
    //->where
    ->first();
    //var_dump(strcmp( str_replace(' ', '', $sentence->details->sentence) , str_replace(' ', '', $request->sentence) ));
    //var_dump( iconv("UTF-8", "ISO-8859-1",str_replace(' ', '', $request->sentence)) );
    //var_dump(mb_detect_encoding(' ', '', $sentence->details->sentence));
Ameer
  • 35
  • 5
  • It's not clear what you're trying to accomplish here. It's very unlikely you're getting ASCII from your request; even if you were, it's a subset of both ISO-8859-1 and UTF-8. Trying `var_dump()` or `dump()` on the actual string values themselves might give you more information? – miken32 May 18 '22 at 17:19
  • 1
    Could you please check string length for both the string after converting request string to UTF-8. I suggest convert both the string and trim it. Also check length of the string. strlen(trim(@iconv('UTF-8', 'UTF-8//IGNORE',$string)); – Bhushan May 18 '22 at 17:46
  • Show us the hex of a string. – Rick James May 23 '22 at 05:56

1 Answers1

-1

You can set up on clientside on which charset it suppose to be like:

<meta charset="utf-8">

or

<form ... accept-charset="utf-8">

Related to https://stackoverflow.com/a/39381595/5663411

tokkerbaz
  • 377
  • 1
  • 6