The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
I.e.
"This is a test. This is also a test."
To : -
"This is a test."
"This is also a test."
Simply splitting the paragraph ala,
echo substr($para,0,strlen($para)/2);
echo substr($para,(strlen($para)/2)+1,strlen($para));
Is not acceptable. Anyone do this quickly? I desperately need it.
Nice example Garin, and your theory of finding the middle, then the closet full stop is spot on.
> I guess the problem is that it takes no account of where you're
> splitting, ie you might be splitting mid word.
Yup, exaclty. It's for a news page on a website.
> Presumably he wants something like:
>
> $half = floor(strlen($paragraph) / 2);
> $sec1 = strrpos(substr($paragraph,0,$half+1),".");
> $sec2 = strpos(substr($paragraph,$half+1),".");
> if (($half-$sec1)<(($half+$sec2)-$half)) {
> $para1=substr($paragraph,0,$sec1+1);
> $para2=trim(substr($paragraph,$sec1+1));
> } else {
> $para1=substr($paragraph,0,($half+$sec2+2));
> $para2=trim(substr($paragraph,($half+$sec2+2)));
> }
>
> Not tested that so maybe it works, maybe it doesn't. :P But the
> theory is, from the middle point of the paragraph, find the nearest
> full stop on either side, whichever is closest, split there. Depends
> on your criteria for splitting though.
Top stuff! Works perfectly! Top of the class. :)
Seriously though, cheers mate. That's saved me some time this morning.
> I'd have done it like this:
>
> $half = $strlen($paragraph) / 2;
> $sec1 = substr($paragraph,0,$half);
> $sec2 = substr($paragraph,($half+1));
>
> Pretty similar though, so why was yours not acceptable? (Though I
> expect PHP has a function that is designed to do this)
I guess the problem is that it takes no account of where you're splitting, ie you might be splitting mid word.
Presumably he wants something like:
$half = floor(strlen($paragraph) / 2);
$sec1 = strrpos(substr($paragraph,0,$half+1),".");
$sec2 = strpos(substr($paragraph,$half+1),".");
if (($half-$sec1)<(($half+$sec2)-$half)) {
$para1=substr($paragraph,0,$sec1+1);
$para2=trim(substr($paragraph,$sec1+1));
} else {
$para1=substr($paragraph,0,($half+$sec2+2));
$para2=trim(substr($paragraph,($half+$sec2+2)));
}
Not tested that so maybe it works, maybe it doesn't. :P But the theory is, from the middle point of the paragraph, find the nearest full stop on either side, whichever is closest, split there. Depends on your criteria for splitting though.
> echo substr($para,0,strlen($para)/2);
> echo substr($para,(strlen($para)/2)+1,strlen($para));
>
> Is not acceptable.
I'd have done it like this:
$half = $strlen($paragraph) / 2;
$sec1 = substr($paragraph,0,$half);
$sec2 = substr($paragraph,($half+1));
Pretty similar though, so why was yours not acceptable? (Though I expect PHP has a function that is designed to do this)
> My dog ate it.
Damn! Foiled!
Nah, I need it quickly, otherwise I'd write it myself! Did one aaaageeessss ago in C++, so it's possible (and pretty easy if I remember).
I.e.
"This is a test. This is also a test."
To : -
"This is a test."
"This is also a test."
Simply splitting the paragraph ala,
echo substr($para,0,strlen($para)/2);
echo substr($para,(strlen($para)/2)+1,strlen($para));
Is not acceptable. Anyone do this quickly? I desperately need it.