-4

I'm just trying to make a php script, which would show ask.fm answer and question, when we put a link. But I don't now how to easy do it, so can you help me?

How should it work:

$link = 'http://ask.fm/username/answer/01234567890';
$check_if_exist = true/false;
if ($check_if_exist == true) {
    $question = question;
    $answer = answer;
}
4

1 回答 1

4

您可以通过检查所述网址的响应代码来检查它。如果响应代码是200,则 URL 存在,否则响应代码将为404.

这是 +/- 伪代码(未经测试),我不保证它会起作用,但是你明白了。

$ch = curl_init('http://ask.fm/username/answer/01234567890');
curl_exec($ch);
$info = curl_getinfo($ch);
$code = $info['http_code'];

if ($code === 200) {
    // question exists
} else {
    // question does not exist
}
于 2013-06-13T15:40:24.693 回答