Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:将字符串包装到文件对象中_Php_String_File_Web Crawler_Fopen - Fatal编程技术网

PHP:将字符串包装到文件对象中

PHP:将字符串包装到文件对象中,php,string,file,web-crawler,fopen,Php,String,File,Web Crawler,Fopen,快速问题: 所以我写了一堆爬行代码,但是我正在爬行的一个网站没有在标签之间包含换行符。因为我已经写了一堆代码,所以我用preg_replace进行了一次快速的黑客攻击,并从我结束的地方继续。问题是,fopen()对字符串不起作用 $string = file_get_contents($url); $string = preg_replace("/>(^\n|\n+)?</", ">\n<", $string); $file = fopen($string, 'r');

快速问题:

所以我写了一堆爬行代码,但是我正在爬行的一个网站没有在标签之间包含换行符。因为我已经写了一堆代码,所以我用preg_replace进行了一次快速的黑客攻击,并从我结束的地方继续。问题是,fopen()对字符串不起作用

$string = file_get_contents($url);
$string = preg_replace("/>(^\n|\n+)?</", ">\n<", $string);
$file = fopen($string, 'r');
while(($buffer = fgets($file)) != false) { ... }
$string=file\u get\u contents($url);

$string=preg_replace(“/>(^\n |\n+)?\n您似乎希望迭代获取页面的每一行。您可以在将其拉入字符串后,使用函数在换行处将字符串拆分为数组:

foreach (explode("\n", $string) as $line) {
    ....
}

这是一个奇怪的愿望…你为什么要这么做?我不想重写我的循环:P loloomg duh!哈哈,谢谢alex!这只需要快速重构就可以实现