现在我有了这个
***FIRST***1DESIGNRESULTSM25Fe415
***Second***Fe415
***Third***1500.0mm
***Fourth***300.0mmX600.0mmCOVER:40.0mm
***Fifth***15ENDJOINT:13SHORTCOLUMN
***Sixth***5472.00Sq.mm.REQD.CONCRETEAREA:174528.00Sq.mm
***Seventh***12-25dia.(3.27%,5890.49Sq.mm.)(Equallydistributed)
***Eighth***8mm
***Ninth***300mmc/c
***Tenth***Puz:3666.60Muz1:292.98Muy1:124.69
***Eleventh***
(NOTE This line need to be removed 0.96(asperCl.39.6,IS456:2000)+++++15ENDJOINT:13Puz:3792.15Muz:320.53Muy:133.87IR:0.85)
***FIRST***1DESIGNRESULTSM25Fe415
***Second***Fe415
***Third***1500.0mm
***Fourth***300.0mmX600.0mmCOVER:40.0mm
***Fifth***15ENDJOINT:13SHORTCOLUMN
***Sixth***5472.00Sq.mm.REQD.CONCRETEAREA:174528.00Sq.mm
***Seventh***12-25dia.(3.27%,5890.49Sq.mm.)(Equallydistributed)
***Eighth***8mm
***Ninth***300mmc/c
***Tenth***Puz:3666.60Muz1:292.98Muy1:124.69
***Eleventh***
(NOTE This line need to be removed :0.96(asperCl.39.6,IS456:2000)++++++15ENDJOINT:13Puz:3792.15Muz:320.53Muy:133.87IR:0.85)
首先,我需要在 First &之间拆分值。 第十一次 并获得本系列的最终版本......
[1]
[M25]
[Fe415]
[Fe415]
[1500.0mm]
[300.0mmX600.0mmCOVER:40.0mm]
[15ENDJOINT]
[5472.00Sq.mm]
[12-25dia.(3.27%,5890.49Sq.mm.)]
[8mm]
[300mmc/c]
[Puz:3666]
[Muz1:292]
[Muy1:124.69]
我尝试了其他一些方法来做到这一点,但遗憾的是它有效;(
还有2000行相同的字符串....我的下一步是将每条记录插入Excel工作表。
提前致谢...:)
答案 0 :(得分:1)
我没有得到你试图在这里实现的模式..
您是否尝试删除所有
***Somestring***
然而,我不明白这种模式 从第一个值1DESIGNRESULTSM25Fe415
获取
[1]
[M25]
[Fe415]
答案 1 :(得分:0)
只需构建一个小脚本即可完成工作。
您必须将日志文件字符串放入变量 $ input 。它甚至可以是数百个日志块。试试看吧,...
你走了:
<?php
$input = 'YOUR_LOG_GOES_HERE';
$splitParts = preg_split('/.*?NOTE\sThis\sline.*?\n/', $input);
foreach ($splitParts as $key => $part) {
$values = splitValues($part);
/**... do somthing with values... like put them in an excel sheet
* or just print them out
*/
echo '<pre>';
print_r($values);
echo '</pre>';
}
function splitValues($part)
{
$splitted = preg_split('/\n/', $part);
$data = array();
/** Match 1. row **/
$match = array();
preg_match_all('/\*\*\*.*?\*\*\*(.*)?DESIGNRESULTS([a-zA-Z]{1,}[0-9]{2})(.*)/', $splitted[1], $match);
$data[] = $match[1][0];
$data[] = $match[2][0];
$data[] = $match[3][0];
/** Match 2. - 4. row **/
for ($i=2; $i <= 4; $i++) {
$data[] = matchRow($splitted[$i]);
}
/** Match 5. row **/
$match = array();
preg_match_all('/\*\*\*.*?\*\*\*(.*)?:.*$/', $splitted[5], $match);
$data[] = $match[1][0];
/** Match 6. row **/
$match = array();
preg_match_all('/\*\*\*.*?\*\*\*([0-9]{1,}.*)?\.REQD.*$/', $splitted[6], $match);
$data[] = $match[1][0];
/** Match 7. row **/
$match = array();
preg_match_all('/\*\*\*.*?\*\*\*(.*)?\(.*\)$/', $splitted[7], $match);
$data[] = $match[1][0];
/** Match 8. - 9. row **/
for ($i=8; $i <= 9; $i++) {
$data[] = matchRow($splitted[$i]);
}
/** Match 10. row **/
$match = array();
preg_match_all('/\*\*\*.*?\*\*\*(Puz:[0-9]{1,}\.[0-9]{1,})(Muz1:[0-9]{1,}\.[0-9]{1,})(Muy1:[0-9]{1,}\.[0-9]{1,})$/', $splitted[10], $match);
$data[] = $match[1][0];
$data[] = $match[2][0];
$data[] = $match[3][0];
return $data;
}
function matchRow($row)
{
$match = array();
preg_match_all('/\*\*\*.*?\*\*\*(.*)/', $row, $match);
return $match[1][0];
}
以下是新字符串的代码:
<?php
$input = '#1-M25Fe415-Fe415-1500.0mm-300.0mmX600.0mm-40.0mm-15-5472.00Sq.mm-174528.00Sq.mm-12-25dia.(3.27%,5890.49Sq.mm.)-8mm-300mmc/c-Puz:3666.60Muz1:292.98Muy1:124.69-';
$data = array();
$data = preg_split('/-/', $input);
$matches = array();
preg_match_all('/(Puz:[0-9]{1,}\.[0-9]{1,})(Muz1:[0-9]{1,}\.[0-9]{1,})(Muy1:[0-9]{1,}\.[0-9]{1,})$/', $data[13], $matches);
$data[13] = $matches[1][0];
$data[14] = $matches[2][0];
$data[15] = $matches[3][0];
print '<pre>';
print_r($data);
print '</pre>';