Jump to content

How to check first 2 letter of string is capital or not


shahzad429

Recommended Posts

<?php

$string1 = 'etd000';
$string2 = 'AA001';

function check( $string ) {
$a = ord($string[0]);
$b = ord($string[1]);
return $a > 64 && $a < 91 && $b > 64 && $b < 91;
}

var_dump(check($string1));
var_dump(check($string2));

function check_alternate($string) {
return (bool) preg_match('/^[A-Z]{2}/', $string);
}

var_dump(check_alternate($string1));
var_dump(check_alternate($string2));

?>

<?php

$string ="Anything you want here"; //your string here

$array=str_split($string);

If(ord($array[0])>=65 AND ord($array[0])<=90)
echo "First letter is Capital";

If(ord($array[1])>=65 AND ord($array[1])<=90)
echo "Second letter is Capital";


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.