标签: file-get-contents

使用PHP检索textarea的值

有谁可能知道如何使用PHP获取HTML文档中特定元素的值?我现在正在做的是使用file_get_contents从另一个网站提取HTML代码,并在该网站上有一个textarea:

<textarea id="body" name="body" rows="12" cols="75" tabindex="1">Hello World!</textarea>
Run Code Online (Sandbox Code Playgroud)

我想做的就是让我的脚本完成,file_get_contents然后拔出"Hello World!" 来自textarea.那可能吗?很抱歉打扰你们,再次,你们给出了一些有用的建议:].

php file-get-contents

3
推荐指数
1
解决办法
3179
查看次数

Perl命令或模块,如Linux"file"命令

我有一个下载文件的脚本,但这些文件在下载之前没有任何关于它们的信息.在为Linux编写时,我刚刚调用qx{ 'file ' . $filename }它来查看它是否是JPEG图像,如果不删除它.但是,我现在正在尝试重写为独立于平台且纯Perl的形式.我已将所有调用转到system{ 'curl', $image_website }LWP :: UserAgent调用,我希望有一些方法可以用某些东西替换对文件的调用.

perl cross-platform file-get-contents

3
推荐指数
1
解决办法
1171
查看次数

如何使用PHP以一种奇怪的方式重定向XML文件?

我试图从我的PHP脚本下载的文件就是这个:

http://www.navarra.es/appsext/DescargarFichero/default.aspx?codigoAcceso=OpenData&fichero=Farmacias/Farmacias.xml 
Run Code Online (Sandbox Code Playgroud)

但我不能既不使用file_get_contents()也不使用cURL.我收到了错误Object reference not set to an instance of an object.

知道怎么做吗?

非常感谢,巴勃罗.

更新以添加代码:

$url = "http://www.navarra.es/appsext/DescargarFichero/default.aspx?codigoAcceso=OpenData&fichero=Farmacias/Farmacias.xml";
$simple = simplexml_load_file(file_get_contents($url));
foreach ($simple->farmacia as $farmacia)
{
    var_dump($farmacia);
}
Run Code Online (Sandbox Code Playgroud)

而且该解决方案由于@Gordon:

$url = "http://www.navarra.es/appsext/DescargarFichero/default.aspx?codigoAcceso=OpenData&fichero=Farmacias/Farmacias.xml";
$file = file_get_contents($url, FALSE, stream_context_create(array('http' => array('user_agent' => 'php' ))));
$simple = simplexml_load_string($file);
Run Code Online (Sandbox Code Playgroud)

php xml curl file-get-contents

3
推荐指数
1
解决办法
3078
查看次数

PHP file_get_contents返回错误

我想知道是否有可能有这样的if语句:

if file_get_contents() returns error code xxx OR xxx
    die();
Run Code Online (Sandbox Code Playgroud)

我不知道如何检查是否file_get_contents()返回错误.

php file-get-contents

3
推荐指数
2
解决办法
1万
查看次数

file_get_contents('php:// input')保持返回空

我正在尝试在我的网站上设置gitkit,但无法通过这一行代码.无论我做什么,都会file_get_contents一直空着.

我已经设置了我的php.ini: always_populate_raw_post_data = On

我的环境是PHP 5.3.3,Apache 2.2.6为localhost.

这是一些代码.

在我的index.php中,我调用google API并尝试使用gmail帐户登录,换句话说,联合登录.

(这是来自Google API控制台)

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/googleapis/0.0.4/googleapis.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/jsapi"></script>
<script type="text/javascript">
  google.load("identitytoolkit", "1", {packages: ["ac"], language:"en"});
</script>
<script type="text/javascript">
  $(function() {
    window.google.identitytoolkit.setConfig({
        developerKey: "HERE_GOES_MY_DEVELOPER_KEY",
        companyName: "Valentinos Pizzaria",
        callbackUrl: "http://localhost/valentinos/callback.php",
        realm: "",
        userStatusUrl: "http://localhost/valentinos/userstatus.php",
        loginUrl: "http://localhost/valentinos/login.php",
        signupUrl: "http://localhost/valentinos/register.php",
        homeUrl: "http://localhost/valentinos/index.php",
        logoutUrl: "http://localhost/valentinos/logout.php",
        idps: ["Gmail", "Yahoo"],
        tryFederatedFirst: true,
        useCachedUserStatus: false,
        useContextParam: true
    });
    $("#navbar").accountChooser();
  });
</script>
Run Code Online (Sandbox Code Playgroud)

我收到IDP响应,登录,并被要求获得权限.返回我的回调页面后,我使用了Google提供的代码示例(如下所示),这一行代码似乎没有正确返回.

我做了什么愚蠢的事吗?

任何帮助将不胜感激.

到目前为止,这里是整个callback.php(现在没有任何HTML): …

php file-get-contents

3
推荐指数
1
解决办法
2万
查看次数

cURL返回空白

我正在尝试以下代码,因为重定向不能使用php file_get_contents,但这没有返回任何内容:

function file_get_contents_curl($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    $data = curl_exec($ch);

    curl_close($ch);

    return $data;
}


$url = 'http://www1.macys.com/shop/product/michael-michael-kors-wallet-jet-set-monogram-ziparound-continental?ID=597522&CategoryID=26846&RVI=Splash_5';
$html = file_get_contents_curl($url);
echo "html is ".$html;
Run Code Online (Sandbox Code Playgroud)

php curl file-get-contents

3
推荐指数
1
解决办法
2941
查看次数

file_get_contents错误地显示图像

我正在尝试将通用网站和网址显示为我自己网站的一部分.这是我正在使用的相对简单的代码的一部分:

browse.php

<?   
$enteredurl = $_GET["url"];
$page = file_get_contents($enteredurl);
echo $page;
?>
Run Code Online (Sandbox Code Playgroud)

如果URls是相对的而不是绝对的,忽略一些链接/图像不起作用的事实,这很好.使用$ _GET访问页面,类似于

browse.php?url = http://itracki.com

网页将按预期显示.然而,当我想要获得其他东西时,比如图像,我会得到类似这样的东西,我认为它是二元的还是什么?

browse.php?url = http://images.itracki.com/2011/06/favicon.png

‰PNG  IHDRóÿa%IDAT8Ëc8sæÌJ0M ```ã3`xaÔ€aa]r#f.–ÄíNIEND®B`‚
Run Code Online (Sandbox Code Playgroud)

我一直在网上寻找并尝试修改页眉,类似于

<? header('Content-type: image/png;'); ?>
Run Code Online (Sandbox Code Playgroud)

但我仍然得到同样混乱的结果.有谁知道我可以实际看到的图像,因为它是,如果我只是通过键入"访问它http://images.itracki.com/2011/06/favicon.png "到地址栏?

谢谢!

php file-get-contents

3
推荐指数
2
解决办法
1万
查看次数

explode()不会用空格分隔字符串?

我试图打开一个文本文件并将其中的名称列表分解为一个数组但是当我var_dump在新数组中我得到这个:

array(1) { [0]=> string(61) "name name name name " }

列表的全部内容都放在数组中的一个单个键字段中.

这是我正在使用的代码:

$ingame_list = file_get_contents('../../../../home/folder/folder/list.txt');
$newarray = explode(" ", $ingame_list);
var_dump($newarray);
Run Code Online (Sandbox Code Playgroud)

如何让每个名称都在新数组中的自己的关键字段中?

php arrays explode file-get-contents

3
推荐指数
1
解决办法
1686
查看次数

使用readfile加载时,为什么我的图像显示不正确

我正在尝试使用其文件路径读取缩略图.

$thumb = "/location/of/image";

$getInfo = getimagesize($thumb);
header('Content-type: ' . $getInfo['mime']);
readfile($thumb);
Run Code Online (Sandbox Code Playgroud)

结果是图像错误图标.

到目前为止我已经尝试过;

  • 检查文件是否存在

var_dump(file_exists($thumb));

结果:

bool(true)
Run Code Online (Sandbox Code Playgroud)
  • 检查getInfo以确保它是一个图像:

    后续代码var_dump($的getInfo);

结果:

array(7) {
  [0]=>
  int(100)
  [1]=>
  int(94)
  [2]=>
  int(2)
  [3]=>
  string(23) "width="100" height="94""
  ["bits"]=>
  int(8)
  ["channels"]=>
  int(3)
  ["mime"]=>
  string(10) "image/jpeg"
Run Code Online (Sandbox Code Playgroud)

}

这似乎是正确的(大小mime类型等)

.使用file_get_contents($ thumb)而不是file_read(一个完整的范围,但我已经用完了想法).

  • 我检查了它正在读取的文件,我可以毫无问题地下载和查看图像,如果我直接从浏览器调用该文件,图像显示正常.所以它看起来不像那样

  • 强制文件下载而不是显示:

    header("Content-Type:application/force-download");

    任何图像编辑器/视图或浏览器都无法识别生成的文件.即使我将下载文件名明确设置为"thumb.jpg",也会出现一系列错误,从"不完整"到"无法识别的格式".

我没有想法!有没有人提出任何其他建议如何调试此问题?

在此先感谢您的建议:)

php file-get-contents readfile

3
推荐指数
1
解决办法
864
查看次数

路由的laravel file_get_contents没有响应

我有一条路线:

Route::group(array('prefix' => 'playlist'), function()
{
   Route::get('raw/{id}', array('as'=>'rawPlaylist', 'uses'=>'PlaylistsController@raw'));
});
Run Code Online (Sandbox Code Playgroud)

当我打开URL时:

http://localhost:8000/playlist/raw/1
Run Code Online (Sandbox Code Playgroud)

一切都很好,页面将加载并显示视图.

在控制器中,我得到了URL:

$url = URL::route('rawPlaylist', 1);
Run Code Online (Sandbox Code Playgroud)

问题: 我想读取视图并将整个视图存储到变量中:

$html = file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)

echo $ url是http:// localhost:8000/playlist/raw/1这是对的.

但这不起作用.我得不到任何回应,而php工匠服务休息.为什么?这有什么不对?

php file-get-contents laravel

3
推荐指数
1
解决办法
5630
查看次数

标签 统计

file-get-contents ×10

php ×9

curl ×2

arrays ×1

cross-platform ×1

explode ×1

laravel ×1

perl ×1

readfile ×1

xml ×1