|
Posted by Rik Wasmus on 10/28/07 15:29
On Sun, 28 Oct 2007 00:05:47 +0200, <182719@rock.com> wrote:
>> you could use
>>
>> ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase );
>>
>
> Thank you all so much. I am more of a big fan of ereg for its
> elegance, however being cryptic and hard to learn!
>
> <?
Use <?php where possible instead of <?. Search the group archives or
google why (searchterm: short_open_tags).
> $testcase = "This should be CaUGht in filter";
>
> print "Testing string > " . $testcase . "<br><br>";
>
> if (ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase ))
Should this not BE caught in the filter? One should use the PCRE (preg_*)
functions, and the match should not be greedy as in the patter above.
> 2) How to in situations where two or more consecutive letters are
> found, to lowecase them EXCEPT 1) if it is a first letter, then it
> should keep it uppercase... and lowercase the remaining letters of the
> word. What has my head swimming is the space issues,.... if they are
> being ignored.
>
> Like, should work this way:
>
> $testcase = "Hello World" ; < passes no problem OK
> $testcase = "HEllo WOrld" ; < should be transformed to "Hello World"
> $testcase = "HeLLo WORLD" ; < should be transformed to "Hello World"
> $testcase = "Hello wORld" ; < should be transformed to "Hello
> world" :) No problem
As indicated elsewhere, indentify the records in need of substitution in
your database using the answer givne in comp.databases.mysql
For those that do need substitution:
function _my_replace_function($match){
$return = substr($match[0],0,1); //first character stays the same
$return .= strtolower(substr($match[0],1)); //the rest should be lowercase
return $return;
}
$string =
preg_replace_callback('/\b\w*?[A-Z]{2,}\w*?\b/','_my_replace_function',$string);
Ideally, one should use a proper locale, substitute strtolower with
mb_strtolower and in UTF-8 mode use this pattern:
'/\b\w*?\p{Lu}{2,}\w*?\b/'
.... to be able to capture and change capitals like 'wÉÏrd' (which are not
in the normal [A-Z] range).
(my newsserver doesn't carry alt.php, dropped)
--
Rik Wasmus
[Back to original message]
|