所以我正在尝试使用以下函数剖析我的列名
function disectColumnName($columnName){
echo "fieldname: " .$columnName. "<br>";
$periodLengths = array("min","hr","dy","wk"); # Array of periodLength Options
$periodLength = $periodLengths[array_search($columnName, $periodLengths)]; # Find which periodLength is used in columnName and sa
$periodDuration = substr($columnName, 0, strpos($columnName,$periodLength));
echo 'periodLength: '.$periodLength . "<br>";
echo 'periodDuration: '.$periodDuration . "<br>";
$movingAverages = array("e","s");
$movingAverageLoc = $movingAverages[array_search($columnName, $movingAverages)];
echo "movingAverageLoc: " .$movingAverageLoc . "<br>";
$startOfString = strpos($columnName,$periodLength)+strlen($periodLength);
$stringLength = strpos($columnName,$movingAverageLoc)-(strpos($columnName,$periodLength)+strlen($periodLength));
# strpos($columnName,$movingAverageLoc) returns blank, should return strpos when movingAverages = "S"
echo "StartOf: ". $startOfString . "<br>";
echo "StrLen: ". $stringLength . "<br>";
$movingAverage = substr($columnName,$startOfString,$stringLength);
echo 'movingAverage: '.$movingAverage;
}
disectColumnName
处于一个循环中,该循环通过以下列标题数组进行处理 -
array(12) { [0]=> string(7) "14min3e" [1]=> string(7) "14min4e" [2]=> string(8) "14min41e" [3]=> string(7) "14min3s" [4]=> string(8) "14min41s" [5]=> string(8) "14min32s" [6]=> string(9) "14min321s" [7]=> string(9) "15min321s" [8]=> string(8) "15min41s" [9]=> string(9) "15min321e" [10]=> string(8) "15min41e" [11]=> string(8) "15min32e" }
问题是以结尾的列标题's'
没有生成正确的StringLength
或movingAverageLoc
(它显示e
而不是S
)。但是,如果列名以 . 结尾'e'
,它可以完美运行,什么给出?
这是当前正在输出的内容:
fieldname: 14min3e
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: 1
movingAverage: 3
fieldname: 14min4e
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: 1
movingAverage: 4
fieldname: 14min41e
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: 2
movingAverage: 41
fieldname: 14min3s
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: -5
movingAverage:
fieldname: 14min41s
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: -5
movingAverage:
fieldname: 14min32s
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: -5
movingAverage:
fieldname: 14min321s
periodLength: min
periodDuration: 14
movingAverageLoc: e
StartOf: 5
StrLen: -5
movingAverage:
fieldname: 15min321s
periodLength: min
periodDuration: 15
movingAverageLoc: e
StartOf: 5
StrLen: -5
movingAverage:
fieldname: 15min41s
periodLength: min
periodDuration: 15
movingAverageLoc: e
StartOf: 5
StrLen: -5
movingAverage:
fieldname: 15min321e
periodLength: min
periodDuration: 15
movingAverageLoc: e
StartOf: 5
StrLen: 3
movingAverage: 321
fieldname: 15min41e
periodLength: min
periodDuration: 15
movingAverageLoc: e
StartOf: 5
StrLen: 2
movingAverage: 41
fieldname: 15min32e
periodLength: min
periodDuration: 15
movingAverageLoc: e
StartOf: 5
StrLen: 2
movingAverage: 32