douleng0794 2016-11-03 15:51 采纳率: 0%
浏览 57

当我尝试从字符串中转义单引号(/')然后将其编码为JSON之前,无法呈现fullcalendar(jquery)

I'm bulding an event calendar via fullcalendar.

i get the events from a php app that i wrote and i transfer them to the fullcalendar via json.

the problem is that when i try to escape the single quote, the fullcalendar does nor render at all.

here is the problamrtic line code:

     foreach ($jsonEvent[$key1] as $key2 => $value2) {
                if ($key2 == "title") {
                    $jsonEvent[$key1][$key2] = str_replace("'","\'", $value2); //this is the problamatic line code that if excecute the fullcalendar will not render
                }
            }
        }
        $jsonString = json_encode($jsonEvent);

when i dont try to escape the single quote, then the fullcalendar render just fine. like in tihs code:

foreach ($jsonEvent[$key1] as $key2 => $value2) {
                if ($key2 == "title") {
                    $jsonEvent[$key1][$key2] = str_replace("'","", $value2); //with this line the fullcalendar render jus fine
                }
            }
        }
        $jsonString = json_encode($jsonEvent);

so, how can i escape the single quote(') and still get the full calendar to render?

FYI: here is the code for rendering the fullcalendar

 <?php  echo "<div id='calendar'></div>
<script>
                   var json = $json_array_for_fullCalendar; // this is the JSON array with the events 


$('#calendar').fullCalendar({


   events:    json,
   fixedWeekCount: false,


        });


</script>"; ?>

can anyone please help? many thanks!

  • 写回答

1条回答 默认 最新

  • dplp5928 2016-11-03 19:42
    关注

    adding this "JSON_HEX_APOS" to the json_encode function worked worked for me

     $jsonString = json_encode($jsonEvent, JSON_HEX_APOS);
    

    cheers!

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!