Hi i'm getting a problem from a small function i wrote and i'm not sure why.
<?php
function guitartuning2array($data) {
/* converts a scale or chord structure into an array */
$sFM = array();
while(strlen($data)>0) {
//check case X# eg. F#
if($data{1}=="#") {
//add X# to array
$sFM[] = substr($data,0,2);
//remove X# from $data
$data =substr_replace($data,'',0,2);
continue;
}
//check case Xb eg. Fb
if($data{1}=="b") {
//add X# to array
$sFM[] = substr($data,0,2);
//remove X# from $data
$data =substr_replace($data,'',0,2);
continue;
}
//only possible case left is x
//add X to array
$sFM[] = substr($data,0,1);
//remove X from $data
$data = substr_replace($data,'',0,1);
//end while;
}
return $sFM;
//end function
}
$tuning_as_array = guitartuning2array("EA#DGbBE");
print_r($tuning_as_array);
?>
i get the following notice, however the script performs the task as it should.
Notice: Uninitialized string offset: 1 in e:\websrv\www\test.php on line 12
Notice: Uninitialized string offset: 1 in e:\websrv\www\test.php on line 21
these are
if($data{1}=="#") {
and i
if($data{1}=="b") {
if i use substr($data,1,1) rather than $data{1}, the script gives no warning notice.
any ideas to why this is happening??