2017-09-06 1 views
0

나는 아래의 content 섹션에 PHP 파일 (html, css 및 javascript)을 가져 오는 방법을 알아 내려고하고 있습니다.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', 

나는 다음과 같은 시도했지만 실패했다 ... 원래이다. 나는 'content' => $adminhelp 그것을에서 당겨 시도 후 file_get_contents (첫 번째 줄)을 추가하고,

그 ... 내 개정 코드로되어 다음

$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, 

무슨 일이야 어떤 아이디어?

+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의 소스 코드를로드하고 있습니다. 이 답변으로 문제가 해결되지 않는 경우

// 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

관련 문제