为搜索结果页面混合使用PHP和HTML

时间:2016-10-20 03:02:23

标签: php html

我正在设置一个使用PHP来布局页面的页面,但我还需要将这个PHP HTML代码插入到PHP页面中以获取搜索功能。搜索在不同的页面上完成,然后将操作发送到结果页面。我试图让PHP和HTML混合在一起。我尝试使用echo没有成功。基本上我需要PHP HTML代码将结果放入$ layout->内容("");

<?php
require_once($_SERVER["DOCUMENT_ROOT"].'/layout/layout.inc.php');
require_once($_SERVER["DOCUMENT_ROOT"].'/functions/general.inc.php');

$layout = new default_layout();

$layout->title('IT KB Search');

$layout->content("<div class='border'>");
$layout->content('<h1>IT Support Knowledge Base - Search Results</h1>');

    if (isset($_GET['q'])) {

        $query = rawurlencode( strip_tags($_GET['q']));
        $timestamp = time();
        $baseUrl = 'https://oursite.atlassian.net/wiki';
        $url = $baseUrl.'/rest/api/content/search?cql=space=KB%20AND%20type=page%20AND%20title~'.$query; 

        // To enable authenticated search: 
        // $url .= "&os_username=$username&os_password=$password";

        $response = file_get_contents($url);
        $response = json_decode($response);

        $results = $response->results;

Echo    '<div>';
Echo    '   <ol>';
            foreach($results as $item) {
Echo    '       <li><strong><a href="';
                $baseUrl. $item-> _links-> webui
Echo    '       " target='_blank'>';
                $item->title
Echo    '       </a></strong></li>';
            }
Echo    '       </ol></div><hr>';

} 

$layout->content("</div>");

$layout->render();
?>

1 个答案:

答案 0 :(得分:0)

您可以将HTML存储到字符串中,然后将其传递给$ layout-&gt; content()函数,就像这样......

public static IObservable<T> AsObservable<T>(this IMessageBroker messageBroker)
{
    return new DelegateObservable(observer => messageBroker.Subscribe<T>(observer.OnNext));
}

public class DelegateObservable<T> : IObservable<T>
{
    private Func<IObserver<T>, IDisposable> subscriber;

    public DelegateObservable(Func<IObserver<T>, IDisposable> subscriber)
    {
        this.subscriber = subscriber;
    }

    public IDisposable Subscribe(IObserver<T> observer)
    {
        return this.subscriber(observer);
    }
}