X
X
xmoonlight2019-07-30 16:24:10
PHP
xmoonlight, 2019-07-30 16:24:10

Arrangement of missing spaces in the text. How to do it right?

All the best!
Answered the question Is there a solution, what would the users write like that? and decided to continue the development of the topic.
If by accident (or intentionally) the words are "glued": written without a space .
How can they be correctly separated (with "the least bloodshed")?
In advance, thank you all for your help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2019-07-30
@xmoonlight

In short, no way. Google and Yandex clearly have algorithms and libraries with such functionality, but I did not find anything similar in the public domain separately. If the problem is a purely "visual" property (lines do not fit into certain blocks or break the layout), then there is 2 way out:
- Change the behavior of blocks with text through css overflow-wrap: break-word;,
- or programmatically break words longer than a certain number of characters into blocks of N characters (and it is more logical to do this is when outputting, not when processing incoming data).
UPD: As an option - isolate long words and pull the api of Google or Yandex to check for "lice".

P
profesor08, 2019-07-30
@profesor08

There are dictionaries, you download them and use them. You break the word into coincidences. Yes, you have to do it manually, but it's just too much. In order for everything to be fast, the dictionary must be translated into a structure convenient for work.
For example, " written without a space", going through the dictionary you will find a match written , there are no words in s , you add it to the first match, then going through it again, you will find the word without , then you will find a space , there will be an ending, you attach it. The result will be " written without spaces ".

S
Sergey c0re, 2019-07-30
@erge

as an option for a head-on solution, make an array of all words (including all declensions and conjugations), replay all words in the text into words with spaces (you can on both sides), then simply remove extra spaces using regex. For example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question