需要一些帮助,多年来一直在解决这个问题,但似乎无法解决它。我在一个名为“Term Year PrNo”的字段中有一些数据。该字段中的数据如下:
[2010-201110]Winter - 2010 - 1st
[2010-201111]Winter - 2010 - 2nd
[2010-201120]Spring - 2011 - 1st
[2010-201121]Spring - 2011 - 2nd
[2010-201130]Summer - 2011 - 1st
[2010-201131]Summer - 2011 - 2nd
[2011-201210]Winter - 2011 - 1st
[2011-201211]Winter - 2011 - 2nd
[2011-201220]Spring - 2012 - 1st
[2011-201221]Spring - 2012 - 2nd
[2011-201230]Summer - 2012 - 1st
[2011-201231]Summer - 2012 - 2nd
[2012-201310]Winter - 2012 - 1st
[2012-201311]Winter - 2012 - 2nd
[2012-201320]Spring - 2013 - 1st
[2012-201321]Spring - 2013 - 2nd
[2012-201330]Summer - 2013 - 1st
我需要使该字段中的每一行数据成为一个单选按钮选择,我设法通过粘贴该字段的内容并将其作为输入字段吐出来做到这一点。我还使用正则表达式来清理输入值的外观——即删除第一个排序字段。到目前为止,一切都很好。我似乎无法解决的问题是我需要根据 2010-2011 年将数据分段并将它们包装在一个名为 yearblock 的 div 类中。2011-2012 | 2012-2013,这样我就可以使用 CSS 很好地安排它们。通过将前一年与今年进行比较,我已经设法弄清楚如何开始 div 类,但在回应我的输入后,我似乎无法弄清楚如何适当地结束。希望这是有道理的,有人可以看看我的代码并指出我正确的方向吗?
<?php
$arrayTermdates = array();
foreach($termsResult->getRecords() as $key => $term)
{
$arrayTermdates[] = $term->getField('Term Year PrNo');
}
$arrayTermdates = array_unique($arrayTermdates);
sort($arrayTermdates, SORT_STRING | SORT_FLAG_CASE);
foreach($arrayTermdates as $termdate)
{
preg_match_all("/\[[^)]+\]/",$termdate,$matches);
$year = str_replace('[', '', $matches[0][0]);
$year = str_replace(']', '', $year);
$year = str_replace(' ', '', substr($year, 0, -2));
$termdate = preg_replace("/\[[^)]+\]/","",$termdate);
/*
/ - opening delimiter (necessary for regular expressions, can be any character that doesn't appear in the regular expression
\[ - Match an opening parenthesis
[^)]+ - Match 1 or more character that is not a closing parenthesis
\] - Match a closing parenthesis
/ - Closing delimiter
*/
if ($previousYear != $year || $previousYear == '')
{
echo '<div class="yearblock">';
echo '<strong>'.$year.'</strong><br />';
}
?>
<div class="term_value_list">
<input name="Termdate[]" type="radio" value="<?php echo $termdate; ?>">
<?php
$TermdatesArray = explode('-',$termdate);
$Termdisplay = $TermdatesArray[0].' '.$TermdatesArray[1].' ['.str_replace(' ', '', $TermdatesArray[2]).' PR]';
echo $Termdisplay;
?>
<!-- I need to echo an </div> for div class yearblock -->