如何替换一个换行/新行在谷歌绘制表与PHP


How to replace a Line break/new line in Google drawtable with PHP

下面的内容打破了我的google.visualization.DataTable。我是从谷歌日历上拉出来的。

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

我在下面添加了最后两行,现在运行正常了。

$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);