2016-11-28 36 views
-2

如何延遲5秒然後使用file_get_contents PHP?如何延遲5秒,然後使用file_get_contents PHP?

我使用此代碼從使用網址的網頁獲取文本。

的index.php

<?PHP 
$text = file_get_contents('https://www.othersite.com/test_1.php'); 
echo strip_tags($text); // If you only need text not html structure 
?> 

https://www.othersite.com/test_1.php

<meta http-equiv="refresh" content="5;url=https://www.othersite.com/test_2.php"> 

https://www.othersite.com/test_2.php

HELLO WORLD. 

當我加載mysite的(的index.php)。如何延遲5秒,然後用file_get_contents,它是會顯示結果HELLO WORLD.

+0

什麼是延遲? – simon

+0

好吧,如果不延遲,當我使用'file_get_contents'與'test_1.php'它會顯示空白數據。我想在使用'file_get_contents'之前延遲5秒鐘重定向到'test_2.php',結果將是'HELLO WORLD.' –

+0

我仍然不明白你想要做什麼。 – simon

回答

1

使用:

sleep(5); // seconds 

功能

3

您可以使用PHP函數sleep

例子:

<?PHP 
sleep(5); //Sleeps for 5 sec 
$text = file_get_contents('https://www.othersite.com/test_1.php'); 
echo strip_tags($text); // If you only need text not html structure 
?> 
+2

好......是的,那是OP問的。但我不認爲他想這樣做。只是另一個XY問題 – Federkun

+0

@Federkun你認爲他想做什麼? –

+1

我不知道。這就是你應該問他 – Federkun