我已经创建了一个脚本,它将用作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, –