2017-09-06 5 views
0

私はPHPファイル(html、css、javascript)を入手し、下記のcontentセクションに読み込む方法を考えています。file_get_contentsの内容を出力する方法

次は、私は次のことを試みたが、失敗してきた元...

function wpse_124979_add_help_tabs() { 

    if ($screen = get_current_screen()) { 
     $help_tabs = $screen->get_help_tabs(); 
     $screen->remove_help_tabs(); 
     $screen->add_help_tab(array(
      'id' => 'my_help_tab', 
      'title' => 'Help', 
      'content' => 'HTML CONTENT', 

です。私は、次は何が間違って私の改正のコード...

$adminhelp = file_get_contents('admin-help.php'); 

function wpse_124979_add_help_tabs() { 

    if ($screen = get_current_screen()) { 
     $help_tabs = $screen->get_help_tabs(); 
     $screen->remove_help_tabs(); 
     $screen->add_help_tab(array(
      'id' => 'my_help_tab', 
      'title' => 'WTV Help', 
      'content' => $adminhelp, 

で任意のアイデアです

file_get_contents(最初の行)を加え、次いで'content' => $adminhelpでそれを引っ張ってみましたか?

+1

あなたの '$ adminhelp'変数は関数のスコープ内にありません。あなたはそれを渡すか、関数内でその行を動かす必要があります。 http://php.net/manual/en/language.variables.scope.php – iainn

+0

@iainnと同様に、スコープ外から '$ adminhelp'を呼び出しています。 '$ adminhelp = file_get_contents( 'admin-help.php');に移動します。あなたの機能の中で。 – AndyWarren

+0

ありがとう、これは働いた。 – Jane

答えて

0

あなたはPHPファイルの出力は$ adminhelp使用として保存する場合:

$adminhelp = file_get_contents('http://YOUR_DOMAIN/admin-help.php'); 

は今、あなたは、$ adminhelpに管理-help.phpのソースコードを読み込んでいます。 Webページの出力を取得するための

別の例は、cURLのです:

// create curl resource 
$ch = curl_init(); 

// set url 
curl_setopt($ch, CURLOPT_URL, "http://YOUR_DOMAIN/admin-help.php"); 

//return the transfer as a string 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

// $output contains the output string 
$adminhelp = curl_exec($ch); 

// close curl resource to free up system resources 
curl_close($ch); 

これは、あなたの質問に答えていない場合は、あなたが受信しているエラーメッセージを記載してください。

+0

ありがとう、私は完全なURLを使用する必要がありました。ありがとう。 – Jane

関連する問題