How to remove hidden characters from text string in PHP?

I find it difficult to match two text strings. One contains some hidden characters from a text string.

I have a text string: "PR and communication" stored in an SQL database. When popped from there, in $database_version , var_dump($database_version) shows a string with 19 bytes.

I sealed (with permission) from a website, some text into a variable, $web_version . Allegedly, the line is "PR and communication", but it does not match the version of the database, i.e. if($database_version == $web_version) NOT true.

var_dump() shows $web_version to have 23 bytes. trim() has no effect, but strip_tags() , but preg_replace( '/[^\PC\s]/u', $web_version ) removes something because subsequently string_var($web_version) shows that the line contains only 14 bytes. He explicitly deleted something, perhaps too much, as the row still does not match $database_version .

Any ideas:

  • find out what was deleted.
  • cut enough to match $ database_version?

PS I do not know how to view a variable in hex code

+5
source share
1 answer
 $trimmedVal = preg_replace("/\s+|[[:^print:]]/, "", $value) 

trim () only removes "\ t \ n \ r \ 0 \ x0B" (see docs ), so use the snippet at the top to remove non-printable characters from the string.

+2
source

Source: https://habr.com/ru/post/1241634/


All Articles