Php将fopen结果保存为字符串
如何将“$buffer”值转换为字符串,并在fopen和fclose函数之外使用它?谢谢Php将fopen结果保存为字符串,php,fopen,fgets,Php,Fopen,Fgets,如何将“$buffer”值转换为字符串,并在fopen和fclose函数之外使用它?谢谢 $handle = @fopen("http://www.example.com/", "r"); if ($handle) { while (!feof($handle)) { $buffer = fgetss($handle, 5000); echo $buffer ; } fclose($handle); } 尝试: $buffer本身就是一
$handle = @fopen("http://www.example.com/", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgetss($handle, 5000);
echo $buffer ;
}
fclose($handle);
}
尝试:
$buffer本身就是一个字符串。循环结束后,不要使用echo打印它,只需将它连接到那里并打印它或将其与所有内容一起使用即可
$buffer = '';
if ($handle) {
while (!feof($handle)) {
$buffer .= fgetss($handle, 5000);
}
fclose($handle);
}
//print the whole stuff:
echo $buffer;
如果您只想获取所有内容,不需要其他处理,请尝试使用:
最简单的方法是使用文件获取内容:
$buffer = file_get_contents("http://www.exemple.com");
只需删除echo$缓冲区;然后将fgetss的=改为。=它将使用字符串值建立缓冲区($buffer)。
fgetss
有点无用。当标签越过换行符时,它将错误地剥离标签。因此,请使用文件中的一个获取内容答案,然后应用标签。非常感谢,这正是我想要的。
$buffer = '';
if ($handle) {
while (!feof($handle)) {
$buffer .= fgetss($handle, 5000);
}
fclose($handle);
}
//print the whole stuff:
echo $buffer;
$buffer = file_get_contents("http://www.exemple.com");
$handle = @fopen("http://www.example.com/", "r");
$buffers = array();
if ($handle) {
while (!feof($handle)) {
$buffers[] = fgetss($handle, 5000);
}
fclose($handle);
}
print_r ( $buffers );