I want to echo the uppercase text of dynamic string data, e.g.

<?
$string = "THIS IS MY Textstring";
?>

and I want to return this:

"THIS IS MY T"

Is there a way to extract only the uppercase part til the first lowercase character appears?

I tried with strpos() and substr(), e.g.

<?
$pos = strpos("[a-z]",$string);
$string = substr($string, $pos);
?>

However it didn't get me anything.

I suppose this is very simple for you.

    $string = "ABCabc ABC abcABC ABC";
    preg_match_all("/([A-Z]+)/s", $string, $matches);
    // $matches contains all upper case matches.
    

      well thx for your fast reply!

      But I only need the uppercase part til the first lowercase letter appears. I don't want the script to get me all uppercases.

      Let's say it looks like this:

      THIS IS ANOTHER Test, yoU KnoW?

      It should only get me "THIS IS ANOTHER T", not the U+K+W on the rest of the string...

      any ideas?

        Change preg_match_all to just preg_match.

          Write a Reply...