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!

    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择