php文件-通过标记将html内容放入数组
更新:到目前为止,此代码仍然有效。仍在鸣叫。php文件-通过标记将html内容放入数组,php,arrays,file,file-get-contents,Php,Arrays,File,File Get Contents,更新:到目前为止,此代码仍然有效。仍在鸣叫。 $trimmed = file('http://www.edvizenor.com/mercy/love/dm8.php'); foreach ($trimmed as $line_num => $line) { if(preg_match("/<td class=\"num\">/", $trimmed[$line_num], $matches)) { $num++; } $Content[$n
$trimmed = file('http://www.edvizenor.com/mercy/love/dm8.php');
foreach ($trimmed as $line_num => $line)
{
if(preg_match("/<td class=\"num\">/", $trimmed[$line_num], $matches))
{
$num++;
}
$Content[$num] .= $trimmed[$line_num];
}
// Example array!
echo $Content[6];
$trimmed=文件('http://www.edvizenor.com/mercy/love/dm8.php');
foreach($line\u num=>$line)
{
if(preg_match(“/”,$trimmed[$line_num],$matches))
{
$num++;
}
$Content[$num]。=$trimmed[$line_num];
}
//示例数组!
echo$Content[6];
////
结束更新
我正在尝试使用php将表内容放入数组中。我想把每个数字后面的所有段落都放到一个数组中 以下是网址: 我需要将每个段落编号的文本内容以及段落编号放入一个数组中。一旦我有,然后我想把他们保存在一个文件夹到一个txt文件命名的段落编号 例如,在我将内容放入正确的数组之后,如果我想调用第#832段,那么我将执行以下操作:
$par = file_get_contents("353.txt");
// Need code to get only number
echo $num;
echo "<br>";
echo $par;
// should echo out:
353
When Mother left for the chapel and I stayed to set the room in order,
I heard these words: Tell all the sisters that I demand that they live
in the spirit of faith towards the superiors at this present time. I
begged my confessor to release me from this duty.
$par=文件获取内容(“353.txt”);
//需要代码才能得到唯一的数字
echo$num;
回声“
”;
回声$par;
//应该呼应出:
353
当母亲去教堂时,我留下来整理房间,
我听到这样的话:告诉所有的姐妹们,我要求她们活下去
在这个时候,本着对上级的信念。我
求我的忏悔者解除我的责任。
我想把整个内容串成一个字符串,然后“爆炸”
$Content=file\u get\u contents(“http://edvizenor.com/mercy/love/dm8.php");
$ContentArray=explode(“,$Content”);
但这越来越复杂了。所以我停止了
有没有关于最好的方法的想法。我总共有1868段和内容。因此,复制和粘贴将是一个很大的工作。谢天谢地,所有的html都是一样的,所以我应该能够找到一个模式并相应地做我想做的事情。但是我无法理解,所以我转向了StackOverflow上的智者:)想法是将url的内容捕获到一个变量中,然后使用domxpath查询它并将其循环到数组中
$dom = new DOMDocument();
@$dom -> loadHTML($html);
$xpath = new DOMXPath($dom);
$nums = $xpath->query("//td[@class='num']");
$paragraphs = $xpath->query("//td[@class='num']/following::td[1]");
for($j = 0; $j < $nums->length; $j++){
$num = $nums->item($j)->nodeValue;
$para = $paragraphs->item($j)->nodeValue;
$para_array[$num] = $para;
}
$dom=newdomdocument();
@$dom->loadHTML($html);
$xpath=newdomxpath($dom);
$nums=$xpath->query(“//td[@class='num']”);
$parations=$xpath->query(“//td[@class='num']/following::td[1]”);
对于($j=0;$j<$nums->length;$j++){
$num=$nums->item($j)->nodeValue;
$para=$parages->item($j)->nodeValue;
$para_数组[$num]=$para;
}
这是示例结果。
就我个人而言,我喜欢用
$dom = new DOMDocument();
@$dom -> loadHTML($html);
$xpath = new DOMXPath($dom);
$nums = $xpath->query("//td[@class='num']");
$paragraphs = $xpath->query("//td[@class='num']/following::td[1]");
for($j = 0; $j < $nums->length; $j++){
$num = $nums->item($j)->nodeValue;
$para = $paragraphs->item($j)->nodeValue;
$para_array[$num] = $para;
}