I have large text files that I read into an array, but before that I take out all the special characters such as tabs, new lines, and returns. However I'm left with all the extra spaces (sometimes as many as 20 or more at a time) because my users are allowed to type spaces in their text. For storage and other manipulation, I don't need all those spaces.
If I explode it I'm left with thousands of empty (null?) elements in the array.
I can take the spaces out before exploding by doing:
which replaces double spaces with single spaces through a loop--which is a bit overkill (but it works), because i can't just replace double spaces with "" because then there's no space between each legitimate word)
any suggestions how to get out the extra spaces (and still leave a single space)? Or should I go ahead and explode into an array and then delete the null (empty?) values--which I don't know how to do. I know pop and push but can't find how to delete a middle element....
any suggestions are welcomed.
If I explode it I'm left with thousands of empty (null?) elements in the array.
I can take the spaces out before exploding by doing:
Code:
$spacesCount= substr_count($ztagsdata," ");
$spacesCount=$spacesCount/2;
echo $spacesCount;
for ($i=1;$i<$spacesCount;$i++)
{
$ztagsdata= str_replace(" ", " ", $ztagsdata);
}
any suggestions how to get out the extra spaces (and still leave a single space)? Or should I go ahead and explode into an array and then delete the null (empty?) values--which I don't know how to do. I know pop and push but can't find how to delete a middle element....
any suggestions are welcomed.
Comment