Intekhab Khan Intekhab Khan - 2 months ago 6
PHP Question

All caps string with space in php

I got to extract string like

"THE NEED OF FOLLOWING A RELIGION "
from string.
I extracted individual words like
THE
,
NEED
,
OF
... but I need complete string of capital letter like
"THE NEED OF FOLLOWING A RELIGION"
but not able to do so, please help.

preg_match_all("/[A-Z]*/", $html, $out);


Thanks

Answer

A very basic modification to the original code to find capitals of more than 1 at a time.

$str='This is a string WITH MIXED CASE words and WE ONLY WANT capitals';
preg_match_all("/[A-Z\s]{2,}/", $str, $out);
echo '<pre>',print_r($out,true),'</pre>';

outputs:

Array
(
    [0] => Array
        (
            [0] =>  WITH MIXED CASE 
            [1] =>  WE ONLY WANT 
        )

)