1

人気のあるハードウェア サイトのユーザーがニュース投稿を「Metro」するために使用する PHP ファイルをいくつか作成しました。記事のタイトルやリンクなどを追加すると、Metro タイル形式で出力されます。

見てみましょう: http://briandempsey.org.uk/Newstool/index.php

ユーザーが送信すると、提供された情報を使用して投稿が作成されます。ここで、PHP またはその他の言語を使用して、その下に生成されたコードを表示し、ユーザーがコピーして貼り付けることができるようにする必要があります。これを行う方法がわかりません。

4

2 に答える 2

6
header('Content-Type: text/plain');
于 2012-08-02T15:02:40.473 に答える
0

メソッドGETを使用してフォームデータを渡すので、代わりに、htmlをプルするためのURLを作成するページにフォームデータを渡すことができます...

index.phpは上記のような形式になり、urlCreator.phpに投稿されます。

form.phpは不要になったため、削除できます。魔法はurlCreator.phpファイルで発生します。

urlCreator.php(NEW)には、次のようなコードが含まれます。

<?php
    // urlCreator.php will get variables passed to it from index.php

    // Now create the url using the passed variables
    $url = "http://briandempsey.org.uk/Newstool/form.php?title=" . $_GET['title'] . "&color=" . $_GET['color'] . "&Articlecontent=" . $_GET['Articlecontent'] //and so on to build the whole url

    //Now get the pages html
    $html = file_get_contents($url);
?>

変数にhtmlが含まれているので、str_replaceを使用してHTMLをクリーンアップするか、必要に応じて操作できます。

<?php
    // Still in urlCreator.php

    // With the html in a variable you could now edit out the divs and echo the results
    $html = str_replace("<div style=\"background-color: #008299; height: auto; width: 100%; margin-left: 10px;\">", "", $html); //removes the intro div
    $html = str_replace("</div>", "", $html); //removes the closing div

    //Finally echo out the html to the page for copy+paste purposes
    echo $html;
?>
于 2012-08-02T19:53:46.513 に答える