我已經創建了一個腳本,它將用作Wordpress的一個插件,其目的是獲取頁面視頻的數據(視頻標題,視頻url ,拇指網址和總視頻)。 我的插件可以工作,但腳本位於加載結果的相同頁面上,因此它保留在Wordpress中。但是我想將執行搜索的腳本外化,因爲我真誠地不希望它們能夠可視化我的PHP源代碼。PHP - 從外部腳本中獲取數據並以當前形式使用它
所以我試圖分開我的腳本,只是把HTML和調用腳本使用「行動」的形式。 但我不知道如何將我的外部腳本的循環傳遞給本地窗體,也不知道如何傳遞變量的值。我試圖使用「返回」和「標題位置」,但它不起作用。
這是我目前有:
的index.php:
<?php
if (isset($_POST['search'])){
$url = $_POST['keyword'];
$parse = "http://example1.com/?k=".$url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
include("form_results_footer.php"); // I include the header of the page with the results (this part is outside the loop because I do not want it to be repeated).
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$counter++;
$title = //something value;
$linkvideo = //something value;
$thumburl = //something value;
include("form_results.php"); //The results of the "foreach" insert them into a separate php in "fieldsets".
}
$totalvideos = $counter;
include("form_results_footer.php"); //Close the form results
} else {
?>
<html>
<form action="" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
<?php
}
?>
好了,上面的代碼工作正常,但我需要外購部分在那裏我得到這個角色的變量在哪裏將接收他們,這樣的事:
- >http://example.com/script.php
<?php
if (isset($_POST['search'])){
$url = $_POST['keyword'];
$parse = "http://example.com/?k=".$url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$counter++;
$title = //something value;
$linkvideo = //something value;
$thumburl = //something value;
}
$totalvideos = $counter;
return $title;
return $linkvideo;
return $thumburl
}
?>
的index.php
<html>
<form action="http://example.com/script.php" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
循環的結果將有以同樣的方式在同一頁面上收集在最初的例子。 我希望你能讓我明白,先謝謝你。
只是爲了清楚我的困惑,這兩個都在你的插件目錄中。對?或在根文件夾? –
實際上,它們位於插件目錄中。是的,我所說的外部文件將在不同的領域。 – Kokox
您可以使用cURL, –