I need to print/list alphabetical(A-Z) chararcters to manage Excel cells. Is there any PHP function to list alphabetic?
I need result as
A1
B1
C1
D1
..
I think you should use the range function:
$a=range("A","Z");
foreach($a as $char)
echo $char."\n";
You can either do:
foreach (range('A', 'Z') as $char) {
echo $char . "\n";
}
Or:
for ($char = 'A'; $char <= 'Z'; $char++) {
echo $char . "\n";
}
If you're looking for a comprehensive set of Excel functionality, then take a look at PHPExcel which provides a lot of methods for manipulating cell addresses and ranges, as well as reading/writing for Excel and various other spreadsheet file formats
This code for display A,B,...,ZY,ZZ.
function print_char($end_no=90, $start_no=65, $prefix_no=0)
{ $vasant='';
if($prefix_no==0)
{
for($set=$start_no; $set<=$end_no; $set++)
{
$vasant.=(chr($prefix_no).chr($set)).', ';
}
}
else
{
for($set=$start_no; $set<=90; $set++)
{
$vasant.=(chr($set)).', ';
}
for($pre_loop=65; $pre_loop<=$prefix_no; $pre_loop++)
{
for($set=$start_no; $set<=90; $set++)
{
if($set>=$end_no && $pre_loop==$prefix_no)
{
$vasant.=(chr($pre_loop).chr($set)).'. ';
break;
}
else
{
$vasant.=(chr($pre_loop).chr($set)).', ';
}
}
}
}
return $vasant;
}
$show=print_char(90,65,90);
echo $show;
You can do it in this way as well: ASCII range used here.
for($i = 65 ; $i<=90; $i++)
{
echo chr($i);
}