Proofing (fixing punctuation, spaces, uppercase letters) a bio page text with php -
i need in trimming bio info users submit inside profiles. there proofing problems: "this bio of mike, of being uppercase no reason!there no space between question mark , word there?also question mar should have space.also after stop sign there should upper case,and spaces between commas,and,this,one"
here thinking:
first i'd trim $bio var
$bio = trim($bio); then i'd add spaces after punctuation marks - pretty sure not correct because replaces every punctuation type comma.
$bio = str_replace(array(",","!","?"),", ", $bio); then i'd turn letters lowercase; won't work becouse need keep uppercase first letter of first word of sentences inside $bio variables.
$bio = strtolower($bio); and i'd upper case first one; need way upper case each first letter of every word separated ! ? - or stop sign, know... except commas.
$bio = strtoupper($bio); hope can help
i have warn looks hopeless.
anyway, can maybe series of regexps:
// replaces , . ! ? (if not followed space) same (\1), // followed space, followed whatever followed before (\2). // note . , ? special characters regexes, have // escape them "\". $bio = preg_replace('#([,\.!\?])(\s)#ms', '\1 \2', $bio); // replace spaces: sequence of 2 or more spaces // replaced 1 space. $bio = preg_replace('# {2,}#ms', ' ', $bio); // ., !, , ? followed lowercase should uppercase // take full monty, ". m" , uppercase all. since uppercase // of ". " remains ". ", keep things simpler. $bio = preg_replace('#[\.!\?] [a-z])#ms', 'strtoupper("\1")', $bio); // replace caps words lowerspace equivalent. // doesn't seem idea though: "i mike, worked nasa" // , nasa becomes nasa? $bio = preg_replace('# ([a-z][a-z]+)#mse', 'strtolower(" \1")', $bio); this way, sentence becomes:
this bio of mike, of being uppercase no reason! there no space between question mark , word there? question mar should have space. after stop sign there should upper case, , spaces between commas, and, this, one
Comments
Post a Comment