[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Ошибка undefined offset?
Страницы: 1, 2
sergeiss
Valeriya12, компактнее моего кода вряд ли сделаешь :)
1. У каждого элемента обрезаю лишние символы: точки, запятые и всё другое возможно безобразие (список можно расширить) и тут же перевожу слово в нижний регистр.
2. Создаю массив, у которого ключами являются сами слова. Если такого элемента еще не было, то он становится равным 1. Если уже был, то увеличивается на 1.
3. Обрати внимание на вывод (тэг pre).
4. Можно еще отсортировать ключи по алфавиту :) Но это уж сама давай делай.


$str="......очень длинная строка.....";
$arr=explode(' ',$str);
$words=array();

foreach( $arr as $key => $val)
{
$value = strtolower(trim( $val, ",.:;\n\r\t"));
$words[$value] = ( !isset( $words[$val]) ) ? 1 : $words[$value]+1;
}

echo '<pre>'.print_r($words,1).'</pre>';


А вот результат:
Свернутый текст
Array
(
[it] => 1
[was] => 21
[the] => 77
[best] => 1
[of] => 55
[times] => 1
[worst] => 1
[age] => 2
[wisdom] => 1
[foolishness] => 1
[epoch] => 2
[belief] => 1
[incredulity] => 1
[season] => 2
[light] => 1
[darkness] => 1
[spring] => 1
[hope] => 1
[winter] => 1
[despair] => 1
[we] => 4
[had] => 10
[everything] => 1
[before] => 3
[us] => 1
[nothing] => 1
[were] => 11
[all] => 3
[going] => 2
[direct] => 2
[to] => 23
[heaven] => 1
[other] => 3
[way—in] => 1
[short] => 1
[period] => 1
[so] => 1
[far] => 1
[like] => 2
[present] => 1
[that] => 9
[some] => 3
[its] => 3
[noisiest] => 1
[authorities] => 1
[insisted] => 1
[on] => 9
[being] => 2
[received] => 2
[for] => 6
[good] => 1
[or] => 2
[evil] => 1
[in] => 4
[superlative] => 1
[degree] => 1
[comparison] => 1
[only.
there] => 1
[a] => 23
[king] => 2
[with] => 14
[large] => 3
[jaw] => 2
[and] => 23
[queen] => 2
[plain] => 2
[face] => 1
[throne] => 2
[england] => 1
[there] => 4
[fair] => 2
[france] => 1
[both] => 1
[countries] => 1
[clearer] => 1
[than] => 4
[crystal] => 1
[lords] => 2
[state] => 1
[preserves] => 1
[loaves] => 1
[fishes] => 1
[things] => 1
[general] => 1
[settled] => 1
[ever.
it] => 1
[year] => 4
[our] => 1
[lord] => 1
[one] => 5
[thousand] => 4
[seven] => 4
[hundred] => 3
[seventy-five] => 2
[spiritual] => 2
[revelations] => 1
[conceded] => 1
[at] => 6
[favoured] => 2
[as] => 6
[this] => 3
[mrs] => 1
[southcott] => 1
[recently] => 1
[attained] => 1
[her] => 3
[five-and-twentieth] => 1
[blessed] => 1
[birthday] => 1
[whom] => 2
[prophetic] => 1
[private] => 1
[life] => 2
[guards] => 1
[heralded] => 1
[sublime] => 1
[appearance] => 1
[by] => 11
[announcing] => 1
[arrangements] => 1
[made] => 2
[swallowing] => 1
[up] => 2
[london] => 1
[westminster] => 1
[even] => 1
[cock-lane] => 1
[ghost] => 1
[been] => 2
[laid] => 1
[only] => 1
[round] => 1
[dozen] => 1
[years] => 1
[after] => 2
[rapping] => 1
[out] => 5
[messages] => 2
[spirits] => 1
[very] => 2
[last] => 1
[past] => 1
[(supernaturally] => 1
[deficient] => 1
[originality)] => 1
[rapped] => 1
[theirs] => 1
[mere] => 1
[earthly] => 1
[order] => 2
[events] => 1
[lately] => 1
[come] => 2
[english] => 1
[crown] => 1
[people] => 2
[from] => 3
[congress] => 1
[british] => 1
[subjects] => 1
[america] => 1
[which] => 4
[strange] => 1
[relate] => 1
[have] => 2
[proved] => 1
[more] => 1
[important] => 1
[human] => 1
[race] => 1
[any] => 4
[communications] => 1
[yet] => 1
[through] => 2
[chickens] => 1
[brood.
france] => 1
[less] => 1
[whole] => 1
[matters] => 1
[sister] => 1
[shield] => 1
[trident] => 1
[rolled] => 1
[exceeding] => 1
[smoothness] => 1
[down] => 3
[hill] => 1
[making] => 1
[paper] => 1
[money] => 1
[spending] => 1
[under] => 1
[guidance] => 1
[christian] => 1
[pastors] => 1
[she] => 1
[entertained] => 1
[herself] => 1
[besides] => 1
[such] => 1
[humane] => 1
[achievements] => 1
[sentencing] => 1
[youth] => 1
[his] => 9
[hands] => 1
[cut] => 1
[off] => 2
[tongue] => 1
[torn] => 1
[pincers] => 1
[body] => 1
[burned] => 1
[alive] => 1
[because] => 1
[he] => 2
[not] => 2
[kneeled] => 1
[rain] => 1
[do] => 1
[honour] => 1
[dirty] => 1
[procession] => 1
[monks] => 1
[passed] => 1
[within] => 1
[view] => 1
[distance] => 1
[fifty] => 1
[sixty] => 1
[yards] => 1
[is] => 2
[likely] => 2
[enough] => 1
[rooted] => 1
[woods] => 1
[norway] => 1
[growing] => 1
[trees] => 1
[when] => 1
[sufferer] => 1
[put] => 1
[death] => 1
[already] => 2
[marked] => 1
[woodman] => 1
[fate] => 1
[be] => 3
[sawn] => 1
[into] => 2
[boards] => 1
[make] => 1
[certain] => 1
[movable] => 1
[framework] => 1
[sack] => 1
[knife] => 1
[terrible] => 1
[history] => 1
[rough] => 1
[outhouses] => 1
[tillers] => 1
[heavy] => 1
[lands] => 1
[adjacent] => 1
[paris] => 1
[sheltered] => 1
[weather] => 1
[day] => 1
[rude] => 1
[carts] => 1
[bespattered] => 1
[rustic] => 1
[mire] => 1
[snuffed] => 1
[about] => 2
[pigs] => 1
[roosted] => 1
[poultry] => 1
[farmer] => 1
[set] => 1
[apart] => 1
[tumbrils] => 1
[revolution] => 1
[but] => 1
[though] => 1
[they] => 3
[work] => 2
[unceasingly] => 1
[silently] => 1
[no] => 1
[heard] => 1
[them] => 1
[went] => 2
[muffled] => 1
[tread] => 1
[rather] => 1
[forasmuch] => 1
[entertain] => 1
[suspicion] => 1
[awake] => 1
[atheistical] => 1
[traitorous.
in] => 1
[scarcely] => 1
[an] => 2
[amount] => 1
[protection] => 1
[justify] => 1
[much] => 2
[national] => 1
[boasting] => 1
[daring] => 1
[burglaries] => 1
[armed] => 1
[men] => 1
[highway] => 1
[robberies] => 1
[took] => 1
[place] => 1
[capital] => 1
[itself] => 1
[every] => 1
[night] => 1
[families] => 1
[publicly] => 1
[cautioned] => 1
[go] => 1
[town] => 1
[without] => 1
[removing] => 1
[their] => 4
[furniture] => 1
[upholsterers'] => 1
[warehouses] => 1
[security] => 1
[highwayman] => 1
[dark] => 1
[city] => 1
[tradesman] => 1
[recognised] => 1
[challenged] => 1
[fellow-tradesman] => 1
[stopped] => 1
[character] => 1
[captain] => 1
[gallantly] => 1
[shot] => 4
[him] => 1
[head] => 1
[rode] => 1
[away] => 1
[mail] => 2
[waylaid] => 1
[robbers] => 1
[guard] => 1
[three] => 1
[dead] => 2
[then] => 1
[got] => 1
[himself] => 1
[four] => 1
[consequence] => 1
[failure] => 1
[ammunition] => 1
[robbed] => 2
[peace] => 1
[magnificent] => 1
[potentate] => 1
[mayor] => 1
[stand] => 1
[deliver] => 1
[turnham] => 1
[green] => 1
[who] => 3
[despoiled] => 1
[illustrious] => 1
[creature] => 1
[sight] => 1
[retinue] => 1
[prisoners] => 1
[gaols] => 1
[fought] => 1
[battles] => 1
[turnkeys] => 1
[majesty] => 1
[law] => 1
[fired] => 3
[blunderbusses] => 1
[among] => 2
[loaded] => 1
[rounds] => 1
[ball] => 1
[thieves] => 1
[snipped] => 1
[diamond] => 1
[crosses] => 1
[necks] => 1
[noble] => 1
[court] => 1
[drawing-rooms] => 1
[musketeers] => 2
[st] => 1
[giles's] => 1
[search] => 1
[contraband] => 1
[goods] => 1
[mob] => 1
[nobody] => 1
[thought] => 1
[these] => 2
[occurrences] => 1
[common] => 1
[way] => 1
[midst] => 1
[hangman] => 1
[ever] => 2
[busy] => 1
[worse] => 1
[useless] => 1
[constant] => 1
[requisition] => 1
[now] => 2
[stringing] => 1
[long] => 1
[rows] => 1
[miscellaneous] => 1
[criminals] => 1
[hanging] => 1
[housebreaker] => 1
[saturday] => 1
[taken] => 1
[tuesday] => 1
[burning] => 2
[hand] => 1
[newgate] => 1
[pamphlets] => 1
[door] => 1
[hall] => 1
[to-day] => 1
[taking] => 1
[atrocious] => 1
[murderer] => 1
[to-morrow] => 1
[wretched] => 1
[pilferer] => 1
[farmer's] => 1
[boy] => 1
[sixpence.
all] => 1
[came] => 1
[pass] => 1
[close] => 1
[upon] => 1
[dear] => 1
[old] => 1
[environed] => 1
[while] => 1
[worked] => 1
[unheeded] => 1
[those] => 2
[two] => 2
[jaws] => 1
[faces] => 1
[trod] => 1
[stir] => 1
[carried] => 1
[divine] => 1
[rights] => 1
[high] => 1
[thus] => 1
[did] => 1
[conduct] => 1
[greatnesses] => 1
[myriads] => 1
[small] => 1
[creatures—the] => 1
[creatures] => 1
[chronicle] => 1
[rest—along] => 1
[roads] => 1
[lay] => 1
)


_____________
* Хэлп по PHP
* Описалово по JavaScript
* Хэлп и СУБД для PostgreSQL

* Обучаю PHP, JS, вёрстке. Интерактивно и качественно. За разумные деньги.

* "накапливаю умение телепатии" (С) и "гуглю за ваш счет" (С)

user posted image
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.