【问题标题】:How to replace a Line break/new line in Google drawtable with PHP如何用 PHP 替换 Google drawtable 中的换行符/换行符
【发布时间】:2013-04-22 18:10:29
【问题描述】:

以下内容破坏了我的 google.visualization.DataTable。我正在从 Google 日历中提取此内容。

// this one has a line break/enter/new line in google calendar after 5
Kanji lessons from 11 to 15 or Kanji lesson's from 1 to 5 
Beginner students dont have matome quiz. They have usual Katakana quiz from ta to po. 

但以下工作正常。

// this does not have it.
Kanji lessons from 11 to 15 or Kanji lesson's from 1 to 5. Beginner students dont have matome quiz. They have usual Katakana quiz from ta to po. 

我尝试了以下方法。但到目前为止,它们都没有奏效。

$description = str_replace("  "," ",$description);

$description_arr=explode("\\n",$description);

$description = implode("<br />", $description_arr);

完整代码

// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['table,corechart']});
google.setOnLoadCallback(drawTable);
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

// start of tabel
function drawTable() {
    var data = new google.visualization.DataTable();
    //data.addColumn('string', 'Calendar Name');
    data.addColumn('string', 'Date Due');
    data.addColumn('string', 'Summary');
    data.addColumn('string', 'Date Created');
    data.addColumn('string', 'Description');
    data.addRows([
<?php
    if(count($events))
    {
        foreach($events->items as $item)
        {
            //$displayName = str_replace("'", "\'", $item->organizer->displayName);
            $summary = str_replace("'", "\'", $item->getSummary());
            $datedue = str_replace("'", "\'", $item->start->date);
            $description = str_replace("'", "\'", $item->description);
            $description = str_replace("&nbsp;&nbsp;"," ",$description);
            // $description_arr=explode("\\n",$description);
            // $description = implode("<br />", $description_arr);
            echo "['".$datedue."','".$summary . "','" . substr($item->created, 0, 10) ."','".$description."' ],\n";

            //echo "['".$displayName."','".$summary."','".$date . "','" . substr($item->created, 0, 10) ."','".$descrption."' ],\n";
        }
    }
    else
    {
        echo "Calendar is private.";
    }
?>

    ]);

    var table = new google.visualization.Table(document.getElementById('table_div'));
    table.draw(data, {showRowNumber: true, allowHtml:true});
}
// end of table

【问题讨论】:

    标签: php newline google-calendar-api line-breaks


    【解决方案1】:

    我在下面添加了最后两行,现在可以正常工作了。

    $summary = str_replace("'", "\'", $item->getSummary());
    $date = str_replace("'", "\'", $item->start->date);
    $description = str_replace("'", "\'", $item->description);
    // replace line breaks with a space
    $description = str_replace("\n"," ",$description);
    $description = str_replace("\r"," ",$description);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 2012-04-08
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多