A-Z
is all the capital letters from A-Z
[A-Z]
just groups the range like parenthesis in algebra to simplify viewing (6*9)(8*3)
[A-Z]|[0-9] either or each range, same as [A-Z0-9]
([A-Z]|[0-9])
Matches either or, same as (A-Z|0-9)
/([A-Z])/
means this is a regular expression NOT a string variable
Code: Select all
<?php
$str1="this Is a Test and it should Work Fine";
$fixedStr=preg_replace("/([A-Z])/","<font size=\"5\">$1</font>",$str1);
echo "<h4>$str1</h4>";
echo "<h5>$fixedStr</h5>";
//-----
echo "<hr />";
//-----
$str2="11th Hour or Maybe 1986 or Possibly 1st 2nd Try";
$fixedStr2=preg_replace("/([A-Z]|[0-9])/","<font size=\"5\">$1</font>",$str2);
echo "<h4>$str2</h4>";
echo "<h5>$fixedStr2</h5>";
?>