H
H
helixly2016-01-13 13:03:22
PHP
helixly, 2016-01-13 13:03:22

How to remove an incomprehensible space character at the end of a word?

Broke my whole head. Parsed text passed through

trim(strtolower(preg_replace("/\s+/, "", $value)));

the output is a string with an incomprehensible whitespace character at the end of the string. And the string size is 2 bytes larger
string(38) "среднеемедицинское "
string(36) "среднеемедицинское"

Where is the joint?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Wolf, 2016-01-13
@mannaro

Are you sure that this character appears at the very beginning, and not somewhere after trim?

A
Aleksey Ratnikov, 2016-01-13
@mahoho

There is not one character, but two, as the output of var_dump()'ov directly tells you. The expression removes whitespace and nonprinting characters:
preg_replace("/\s+|/, "", $value)

X
xmoonlight, 2016-01-13
@xmoonlight

trim(strtolower(preg_replace_all("/[^.,:-а-яА-Я0-9a-zA-Z ]+/usi", "", $value)));

R
romy4, 2016-01-13
@romy4

\s+ replaces only 0x20, 0x9, 0xA, 0xD, which is directly stated in the manual. If something looks like a gap, it can safely not be. And there are also various typographic non-breaking spaces, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question