标签: file-get-contents

PHP重试脚本直到成功或错误

我正在尝试创建一个PHP脚本,重试另一个PHP脚本最多3次,直到显示错误.我想也许这可以使用php循环完成?如果代码第一次成功运行,则不需要重试3次,但是,如果第一次不能正常工作,那么它应该重试PHP脚本最多3次,直到显示错误消息.

使用PHP编码,我设法创建一个脚本,使用"file_get_contents"从另一个位置抓取/获取内容,然后为每个单词/数据提供一个php变量.所有这一切都是通过在stackoverflow上获得其他成员的帮助来完成的(我非常感谢).下面的代码就是这一切:

$searchdata = file_get_contents('http://www.example.com');

list($no1, $no2, $no3, $no4, $no5, 
     $no6, $no7, $no8, $no9) = explode(" ", $searchdata);
Run Code Online (Sandbox Code Playgroud)

所以,我想添加一些循环,重试这个脚本最多3次; 如果它第一次不起作用.要确定脚本是否在第一次/第二次/第三次运行,使用"file_get_contents"时应找到文本"#endofscript"或"failure".如果显示除"#endofscript"或"failure"之外的任何其他内容,则应将其视为错误,并应循环直至找到.如果在第三次尝试后仍未找到,是否会显示错误消息?如"错误 - 请再试一次".

感谢您的所有帮助,我将感谢您的每一个回复.如果您需要更多详细信息,请随时提出.而且,我真的很感激这一点.:)

php loops file-get-contents

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

文件获取内容无法打开流未经授权

我正在尝试使用file_get_contents.I确保在php.ini中启用了allow_url_fopen.截至目前,它告诉我:

[function.file-get-contents]:无法打开流:HTTP请求失败!HTTP/1.1 401未经授权

我正在做的就是以下内容,我可以通过浏览器访问它而没有任何问题.

$url=('http://site/@api/users/=john_smith@site.com/properties');
$xmlString=file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)

我相信这是一个身份验证问题,但不确定如何从脚本本身提供正确的凭据.任何想法将不胜感激.

php http httpwebrequest file-get-contents

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

PHP file_get_contents 在 Google 搜索上?

我正在尝试使用 PHP 返回 Google 搜索结果的 HTML。

例如

<?php
$file = file_get_contents('http://www.example.com',false);
echo $file;
?>
Run Code Online (Sandbox Code Playgroud)

将返回 example.com 的 HTML 内容。问题是,当我尝试在 Google 搜索 URL(例如http://www.google.com/#sclient=psy&hl=en&q=cats )上执行此操作时,它会从 Google 主页返回 HTML,而不是搜索“猫”的搜索结果。

做到这一点最简单的方法是什么?

php file-get-contents

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

json_decode file_get_contents帮助

<?php
$json = file_get_contents('http://tiny.cc/ttrhelp');

$obj = json_decode($json);
$example = $obj->rooms->displayName;
?>

Name: <?php echo $example; ?>
Run Code Online (Sandbox Code Playgroud)

试图显示'displayName'的值,但它没有显示

php json file-get-contents

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

使用PHP解析Web页面内容

我认为这是一个简单的问题,但我已经做了我所知道的但仍然没有工作.我想从这个链接获得输出:

http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en

您可以在浏览器上粘贴并查看它.有一些文字输出.我试过PHP中的一些函数,比如file_get_contents和curl.我没有使用ajax或JavaScript,因为我不熟悉它.最后,我正在与XAMPP合作.

php curl file file-get-contents php-parser

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

如何从html页面获取文本链接?

我想从这个网页上获得链接" http://www.w3schools.com/default.asp "和" http://www.google.com ".我想要<a>里面的标签链接<div class="link">,还有很多其他<a>标签在这个页面,我不想要他们.我怎样才能检索特定的链接?谁能帮我?

<div class="link">
<a href="http://www.w3schools.com/default.asp">
<h4>W3 Schools</h4>
</a>
</div>
<div class="link">
<a href="http://www.google.com">
<h4>Google</h4>
</a>
</div>
Run Code Online (Sandbox Code Playgroud)

html php file-get-contents

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

file_get_contents无法打开流:HTTP请求失败!HTTP/1.1 500内部服务器错误

我正在通过URL检索外部源中的图像并将其保存到我的网络服务器中.不幸的是,我有时会收到以下错误:无法打开流:HTTP请求失败!HTTP/1.1 500内部服务器错误.

当我使用浏览器访问给定的URL时,图像显示并且有效.网址:

http://****.com/00/s/NTgwWDcyNg==/z/7LEAAMXQVT9TCcxx/$_85.JPG
Run Code Online (Sandbox Code Playgroud)

我使用的代码:

$opts = array('http'=>array('header' => "User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1\r\n", 'timeout' => "360"));
$context = stream_context_create($opts);                                         
$imageString = file_get_contents(urldecode(urlencode($filename)), false, $context);                                            
$save = file_put_contents(dirname(dirname(__FILE__)) . '/tmp/' . $id . '_' . $sequenceNumber . '.jpg', $imageString);
Run Code Online (Sandbox Code Playgroud)

任何人都知道为什么我会收到500错误?

php image urlencode file-get-contents

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

php中的file_get_contents()超时

我知道 php 没有提供超时选项,因为它是从服务器端运行的。但我的逻辑需要超时。请解决这个案例

我的 PHP: login.php :-

$forms_values = $_POST;
$url = "http://sample.com/sample?params=$forms_values";
$resp = file_get_contents($url);
// It takes much time if sample.com is down.
// so need to set time out here.
$response = json_decode($resp, true);
....
....
if ($response["auth"] == "yes"){
   header("index.php");
}
Run Code Online (Sandbox Code Playgroud)

我的 html index.html :-

<form action="login.php" method="post" id="clientLogin">
    <div>
        <input id="username" placeholder="Email or Username" type="text" name="luser" size="30" value="">
    </div>
    <div>
        <input id="passwd" placeholder="Password" type="password" name="lpasswd" size="30" value="">
    </div>
<input class="btn" type="submit" value="Sign In">
</form>
<script …
Run Code Online (Sandbox Code Playgroud)

javascript php timeout file-get-contents

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

如何使用php从文本文件中获取x个字符?

我正在尝试从外部文本文件中获取大约200个字母/字符(包括空格)。我有代码来显示要包含的文本,但是要获得某些字母我不知道。我再一次不是在说线,我的意思是字母。

<?php
    $file = "Nieuws/NieuwsTest.txt";
    echo file_get_contents($file) . '<br /><br />';
?>
Run Code Online (Sandbox Code Playgroud)

php string text substr file-get-contents

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

如何检查file_get_contents在PHP中返回false的原因

我尝试这样做:

$urls = array(


    "https://www.gov.sg/"




);



    foreach ($urls as $url) {
        d($url);
      //  $url = "http://www.google.com";
    $data = file_get_contents($url);
    d($data);

}
Run Code Online (Sandbox Code Playgroud)

d() 是像 var_dump() 一样的第三方函数。

我不断得到 $data = false。似乎域中的任何页面都在这样做。

当我尝试另一个域(如 google.com)时,它奏效了。

该页面有效,我在浏览器上尝试过。

以下类似的帖子提出了 URL 编码问题,并启用了 allow_url_fopen,但这些在这里并不真正适用: PHP file_get_contents 返回 false PHP file_get_contents 返回 false

为什么函数返回false?另外,一般来说,有没有办法检查为什么 file_get_contents 返回 false?PHP 有没有办法转储错误?

php debugging error-handling file file-get-contents

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