2014-01-21 3 views
-3

PHP 함수에서 echo 문을 숨기는 플래그가 있습니까? echo 문이 인쇄되는 시점을 제어 할 수 있기를 원합니다. 다음은 echo 명령문을 제어하기위한 스위치의 예제 함수입니다. 이 기능은 아무것도 후 설치 상태를 에코하고, 그러나 그것은 가장 적합한 사용하지하려면PHP에서 에코를 멈추게하는 플래그

function create_liturgical_calendar($year) { 
    if (!isset($year)) { 
     $year = get_year(); 
    } 

    global $add_data, $skip; 

    echo "<div style='border-bottom: 4px solid #404040;'>year ".$year." add data ".$add_data." skip ".$skip."</div><div style='height: 92%; overflow: auto;'><br/>"; 

    $Baptism_of_the_Lord_date = get_Baptism_of_the_Lord($year); 
    echo 'Baptism of the Lord '.$Baptism_of_the_Lord_date->month.' '.$Baptism_of_the_Lord_date->date.' '.$Baptism_of_the_Lord_date->year.' '.$Baptism_of_the_Lord_date->date_string.'<br/>'; 

    $Ash_Wednesday_date = get_Ash_Wednesday_date($year); 
    echo 'Ash Wednesday will be '.$Ash_Wednesday_date->month.' '.$Ash_Wednesday_date->date.' '.$Ash_Wednesday_date->year.' '.$Ash_Wednesday_date->date_string.'<br/>'; 

    $Annunciation_date = get_Annunciation_date($year); 
    echo 'Annunciation will be '.$Annunciation_date->month.' '.$Annunciation_date->date.' '.$Annunciation_date->year.' '.$Annunciation_date->date_string.'<br/>'; 

    $Palm_Sunday_date = get_Palm_Sunday_date($year); 
    echo 'Palm Sunday will be '.$Palm_Sunday_date->month.' '.$Palm_Sunday_date->date.' '.$Palm_Sunday_date->year.' '.$Palm_Sunday_date->date_string.'<br/>'; 

    $Holy_Thursday_date = get_Holy_Thursday_date($year); 
    echo 'Holy Thursday will be '.$Holy_Thursday_date->month.' '.$Holy_Thursday_date->date.' '.$Holy_Thursday_date->year.' '.$Holy_Thursday_date->date_string.'<br/>'; 

    $Good_Friday_date = get_Good_Friday_date($year); 
    echo 'Good Friday will be '.$Good_Friday_date->month.' '.$Good_Friday_date->date.' '.$Good_Friday_date->year.' '.$Good_Friday_date->date_string.'<br/>'; 

    $Holy_Saturday_date = get_Holy_Saturday_date($year); 
    echo 'Holy Saturday will be '.$Holy_Saturday_date->month.' '.$Holy_Saturday_date->date.' '.$Holy_Saturday_date->year.' '.$Holy_Saturday_date->date_string.'<br/>'; 

    $Easter_date = get_Easter_date($year); 
    echo 'Easter will be '.$Easter_date->month.' '.$Easter_date->date.' '.$Easter_date->year.' '.$Easter_date->date_string.'<br/>'; 

    $Divine_Mercy_date = get_Divine_Mercy_date($year); 
    echo 'Divine Mercy will be '.$Divine_Mercy_date->month.' '.$Divine_Mercy_date->date.' '.$Divine_Mercy_date->year.' '.$Divine_Mercy_date->date_string.'<br/>'; 

    $Ascension_date = get_Ascension_date($year); 
    echo 'Ascension will be '.$Ascension_date->month.' '.$Ascension_date->date.' '.$Ascension_date->year.' '.$Ascension_date->date_string.'<br/>'; 

    $Pentecost_date = get_Pentecost_date($year); 
    echo 'Pentecost will be '.$Pentecost_date->month.' '.$Pentecost_date->date.' '.$Pentecost_date->year.' '.$Pentecost_date->date_string.'<br/>'; 

    $Most_Holy_Trinity_date = get_Most_Holy_Trinity_date($year); 
    echo 'Most Holy Trinity will be '.$Most_Holy_Trinity_date->month.' '.$Most_Holy_Trinity_date->date.' '.$Most_Holy_Trinity_date->year.' '.$Most_Holy_Trinity_date->date_string.'<br/>'; 

    $Corpus_Christi_date = get_Corpus_Christi_date($year); 
    echo 'Corpus Christi will be '.$Corpus_Christi_date->month.' '.$Corpus_Christi_date->date.' '.$Corpus_Christi_date->year.' '.$Corpus_Christi_date->date_string.'<br/>'; 

    $Most_Sacred_Heart_date = get_Most_Sacred_Heart_date($year); 
    echo 'Most Sacred Heart will be '.$Most_Sacred_Heart_date->month.' '.$Most_Sacred_Heart_date->date.' '.$Most_Sacred_Heart_date->year.' '.$Most_Sacred_Heart_date->date_string.'<br/>'; 

    $Immaculate_Heart_date = get_Immaculate_Heart_date($year); 
    echo 'Immaculate Heart will be '.$Immaculate_Heart_date->month.' '.$Immaculate_Heart_date->date.' '.$Immaculate_Heart_date->year.' '.$Immaculate_Heart_date->date_string.'<br/>'; 

    $Christ_the_King_date = get_Christ_the_King_date($year); 
    echo 'Christ the King will be '.$Christ_the_King_date->month.' '.$Christ_the_King_date->date.' '.$Christ_the_King_date->year.' '.$Christ_the_King_date->date_string.'<br/>'; 

} 
+0

필자는 테이블에서 쿼리가 아닌 문자열을 생성한다고 생각했습니다. 홀리 캘린더 및 이벤트와 관련된 일정, 날짜 및 기타 자료를 저장하는 데이터베이스 스키마를 만드는 것이 좋습니다. 이렇게하면 각 날짜 또는 이벤트에 플래그를 지정할 수 있으며 배포 할 때 각 행의 플래그에 따라 ** echo **를 조절할 수 있습니다. 깃발, 기한, 이벤트 유형 등에 따라 스타일을 조절할 수 있습니다. – datelligence

+0

왜 에코를 '중지'해야합니까? 왜 스위치를 사용하면 어떤 문자열을 제어 할 수 있습니까? – anthonygore

답변

0

에코 전환 할 수있는 일반 플래그가 아니므로처럼 보이는이 가장 좋은 방법은 함수를 작성하는 것입니다.

$print = true; 

    function print_echo ($print_text) { 
     if ($print) echo $print_text; 
    } 

    print_echo ('Print if true'); 
0
if (....your condition) { 
    echo ... 
} 
elseif { 
    echo ... 
} 
else { 
    echo ... 
} 
//etc... 

or 

switch ($someVar) { 
    case 0: 
    echo ... 
    break; 
    case 1: 
    echo ... 
    break; 
    case 2: 
    echo ... 
    break; 
} 

조건은 ... 당신의 깃발입니다.

function echoThings() { 
    echo //etc 
} 

if (!$echoOff) { 
    echoThings(); 
} 

이 기능을 비활성화해야하는 경우에만 $echoOff = true을 설정하십시오.

3

에코를 중지하는 유일한 방법은 출력 버퍼링을 사용하는 것입니다. 예 :

ob_start(); 
echo 'Hello World'; 
ob_end_clean(); 

출력을 생성하지 않습니다. 여기

상세 정보 : http://au2.php.net/manual/en/intro.outcontrol.php

+0

사실,하지만 도움이된다고 생각하지 않습니다. 결과적으로 그의 경우에는 출력이 항상 꺼집니다. 마치 'echo'를 제거한 것처럼 말입니다. 그는 여전히 출력 버퍼링을 변경하는 조건이 필요하므로 조건 적으로 상황을 반향시킬 수 있습니다. 함수가 적절하게 나뉘어 진다면, if 문은 필요한 것을 정확히 수행해야합니다. – m59

+0

나는 당신이 말하는 것을보고 있지만, PHP 문에서 에코 (echos)를 방지하는 방법과 같은 주된 질문에 답하려고합니다. 내가 제시 한 문제를 고려해 볼 때 왜 실제로 그렇게해야하는지 분명하지 않지만 동의한다. 그가 추가 정보를 제공하면 그에 따라 내 대답을 업데이트/삭제할 것입니다. – anthonygore

+0

그것은 좋은 대답, 나는 upvoted. 그것은 단지 나쁜 질문입니다 :) – m59

관련 문제