小编tad*_*obi的帖子

在PHP中使用try/catch和cURL

我以为我已经解决了这个问题,但我显然没有,并且希望有人能够对我做错了什么有所了解.我试图获取一段PHP代码来检查服务器上的文件并根据响应执行操作.该文件是一个简单的文本文件,上面写有"true"或"false"字样.如果文件存在或返回为"true",则脚本将转到一个URL.如果它不存在(即服务器不可用)或返回为"false",则脚本转到第二个URL.以下是我到目前为止使用过的代码片段.

$options[CURLOPT_URL] = 'https://[domain]/test.htm';

$options[CURLOPT_PORT] = 443;
$options[CURLOPT_FRESH_CONNECT] = true;
$options[CURLOPT_FOLLOWLOCATION] = false;
$options[CURLOPT_FAILONERROR] = true;
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_TIMEOUT] = 10;

// Preset $response var to false and output
$fb = "";
$response = "false";
echo '<p class="response1">'.$response.'</p>';

try {
    $curl = curl_init();
    echo curl_setopt_array($curl, $options);
    // If curl request returns a value, I set it to the var here. 
    // If the file isn't found (server offline), the try/catch fails and var should stay as false.
    $fb = …
Run Code Online (Sandbox Code Playgroud)

php curl

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

从博客中按名称排除Wordpress类别

我有一个包含类别列表的WP博客.我有一个特定的模板应用于一个名为"新闻"的类别,这个类别很好并且有效,但现在我需要确保此类别中的帖子不包含在主博客中.我已经尝试了几点,但对我来说还没有成功.任何建议?

由于我正在开发一个dev/test/prod环境,这些环境都是由不同的人设置的(......叹气......),所以相同的类别都有不同的id,所以我希望从类别名称中删除它.

干杯,

Ť

php wordpress

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

标签 统计

php ×2

curl ×1

wordpress ×1