I have a large word list in a simple text document (80K words) that goes like this:
needy
needier, neediest, neediness
need
nefarious
nefariously, nefariousness
negate
negated, negates, negating
I would like to transform it to something like this:
needy needy
needy needier
needy neediest
needy neediness
need need
nefarious nefarious
nefarious nefariously
nefarious nefariousness
negate negate
negate negated
negate negates
negate negating
How would you advise me to do? I can do some php mysql, or I can work on Excel.
The code opens your text file and grabs them into an array, splits them into chunks of 2's. It is iterated through a loop and the second array element is exploded using comma and concatenated to the first element and then added to a new array.
<?php
echo "<pre>";
$arr = file('stats.txt',FILE_IGNORE_NEW_LINES); //<--- Point the filename of your text document
$arr = array_chunk($arr,2);
$new_arr = array();
foreach($arr as $k=>$arr1)
{
$v = explode(',',$arr1[1]);
foreach($v as $val)
{
$new_arr[]=$arr1[0]." ".trim($val);
}
}
print_r($new_arr);
OUTPUT :
Array
(
[0] => needy needier
[1] => needy neediest
[2] => needy neediness
[3] => nefarious nefariously
[4] => nefarious nefariousness
[5] => negate negated
[6] => negate negates
[7] => negate negating
)