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条)

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图