verfaa
Профессор
- Регистрация
- 29 Янв 2007
- Сообщения
- 417
- Реакции
- 49
- Автор темы
- #1
Всем привет. Необходимо, используя PHP 5.6, разбить текст, длина которого более 3000 символов на куски не более 500 символов. Но при этом нужно учитывать предложения. Текст может содержать теги.
Например имеем текст, в нём 1398 символов:
Необходимо на выходе получить массив:
Подскажите как это лучше всего сделать.
Например имеем текст, в нём 1398 символов:
Financial, commercial, legal, and intellectual factors changed the size of encyclopedias. During the <a href="/wiki/Renaissance" title="Renaissance">Renaissance</a>, middle classes had more time to read and encyclopedias helped them to learn more. Publishers wanted to increase their output so some countries like Germany started selling books missing alphabetical sections, to publish faster. Also, publishers could not afford all the resources by themselves, so multiple publishers would come together with their resources to create better encyclopedias. When publishing at the same rate became financially impossible, they turned to subscriptions and serial publications. This was risky for publishers because they had to find people that would pay all upfront or make payments. When this worked, capital would rise and there would be a steady income for encyclopedias. Later, rivalry grew, causing copyright to occur due to weak underdeveloped laws. Some publishers would copy another publisher's work to produce an encyclopedia faster and cheaper so consumers did not have to pay a lot and they would <a href="/wiki/encyclopedias" title="Renaissance">sell more</a>. Encyclopedias made it to where middle-class citizens could basically have a small library in their own house. Europeans were becoming more curious about their society around them causing them to revolt against their government.
Необходимо на выходе получить массив:
Код:
$result = [
// 393 символа
0 => "Financial, commercial, legal, and intellectual factors changed the size of encyclopedias. During the <a href=\"/wiki/Renaissance\" title=\"Renaissance\">Renaissance</a>, middle classes had more time to read and encyclopedias helped them to learn more. Publishers wanted to increase their output so some countries like Germany started selling books missing alphabetical sections, to publish faster.",
// 478 символов
1 => "Also, publishers could not afford all the resources by themselves, so multiple publishers would come together with their resources to create better encyclopedias. When publishing at the same rate became financially impossible, they turned to subscriptions and serial publications. This was risky for publishers because they had to find people that would pay all upfront or make payments. When this worked, capital would rise and there would be a steady income for encyclopedias.",
// 407 символов
2 => "Later, rivalry grew, causing copyright to occur due to weak underdeveloped laws. Some publishers would copy another publisher's work to produce an encyclopedia faster and cheaper so consumers did not have to pay a lot and they would <a href=\"/wiki/encyclopedias\" title=\"Renaissance\">sell more</a>. Encyclopedias made it to where middle-class citizens could basically have a small library in their own house.",
// Оставшаяся часть - 117 символов
3 => "Europeans were becoming more curious about their society around them causing them to revolt against their government."
];
Подскажите как это лучше всего сделать.