【发布时间】:2011-11-24 14:51:43
【问题描述】:
我想包含一个外部文件,然后获取所有内容,删除页面上唯一的 HTML <br /> 并替换为 , 并将其触发到数组中。
datafeed.php
john_23<br />
john_5<br />
john_23<br />
john_5<br />
grabber.php
<?php
// grab the url
include("http://site.com/datafeed.php");
//$lines = file('http://site.com/datafeed.php);
// loop through array, show HTML source as HTML source.
foreach ($lines as $line_num => $line) {
// replace the <br /> with a ,
$removeBreak = str_replace("<br />",",", $removeBreak);
$removeBreak = htmlspecialchars($line);
// echo $removeBreak;
}
// fill our array into string called SaleList
$SaleList = ->array("");
我想从服务器目录加载一个 php 文件,获取该文件的 HTML 内容并将其放入一个可用的数组中。
看起来像
$SaleList = -getAndCreateArray from the file above >array("");
$SaleList = ->array("john_23, john_5, john_23");
【问题讨论】:
-
include()在远程 URL 上是危险的。您将完全控制您的脚本的外部服务器,因此完全控制您的网站。除此之外……还有问题吗?你没有提到有问题,所以如果这段代码工作正常,那为什么要发布呢? -
include 是你知道的唯一一个文件操作符吗? file()、file_get_contents() 呢?
-
@MarcB 这个代码不起作用。
-
@Marc B:粗略查看一下他发布的代码表明它运行不正常。他的问题可以概括为“我的代码不起作用。我怎样才能改变它以使其工作?”
-
@Asaph:是的,也许 OP 实际上应该说出问题所在。我可以看到他在使用
$removeBreak却没有定义它,但不知道 OP 实际希望这段代码做什么,这可能只是一些死代码。