我有一行像这样的行,这些是来自搜索的PHP代码的html输出行。
这是浏览器输出页面源(不是服务器源)
**<!DOCTYPE html>
<html>
<head>
<meta`enter code here` content="text/html; charset=windows-1252" http-equiv="content-type">
<title>my page</title>
</head>
<body>
<div style="text-align: center;">
<title>My Page</title>
<form name="myform" action="systemmonitor.php" method="GET">
<div align="center">My page<br>
<br>
<input name="sea1" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea2" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea" value="submit" type="submit"><br>
<br>
data00,data01,data02,data03, , , and so on
data10,data11,data12,data13, , , and so on
data20,data21,data22,data23, , , and so on
(and so on in rows)
<br>
</div>
</form>
</div>
</body>
</html>
这是浏览器服务器源(php)
**<!DOCTYPE html>
<html>
<head>
<meta`enter code here` content="text/html; charset=windows-1252" http-equiv="content-type">
<title>my page</title>
</head>
<body>
<div style="text-align: center;">
<title>My Page</title>
<form name="myform" action="systemmonitor.php" method="GET">
<div align="center">My page<br>
<br>
<input name="sea1" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea2" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea" value="submit" type="submit"><br>
<br>
<?php
$searchthis = $_GET["sea1"];
$matches = array();
$handle = @fopen("sources.csv", "r");
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle);
if(strpos($buffer, $searchthis) !== FALSE)
$matches[] = $buffer;
}
fclose($handle);
}
//show results:
$myString = implode( ', ', $matches );
print_r($myString);
?><br>
<br>
</div>
</form>
</div>
</body>
</html>
现在,在真实的页面里,data0,data1,data2 ......是一个php代码,从上面的html表单中制作这些东西,现在php输出我不会看到什么,但我想转换变量,并只显示我想要的变量,这样的东西就可以了:
var parsed[0][0]=data00;
var parsed[0][1]=data01;
var parsed[0][2]=data02;
var parsed[0][3]=data03;
var parsed[1][0]=data10;
0,X(X是colume的编号)
1,X(X是行数)
然后我只显示我想要的数据。
例如,我将此代码放在页面的某个位置:
document.write(parsed[0][3]);
data00 data01只是php之前的自定义数据。
我怎么能做这个转换?
答案 0 :(得分:0)
这是你想要的吗?
// the string containing the data
var externalData = 'one, two, three\n'
+ 'four, five, six\n'
+ 'seven, eight, nine';
// split the string into rows, and split each row into cells
var parsed = externalData.split('\n').map(function(row) {
return row.split(', ');
});
console.log(parsed[0][1]); // 'two'