douhuanbai6729 2014-01-21 03:02
浏览 40
已采纳

标志在php中停止回声

Is there a flag to hide echo statements in a php function. I want to be able to control when the echo statements are printed. Here is a sample function where I want a switch to control the echo statements.

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

}
  • 写回答

3条回答 默认 最新

  • dpjpo746884 2014-04-01 21:06
    关注

    Looks like since there isn't a general flag to toggle echo, the best thing is to write a function.

      $print = true;
    
      function print_echo ( $print_text ) {
             if ( $print ) echo $print_text;
      }
    
      print_echo ('Print if true');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键