当我尝试从字符串中转义单引号(/')然后将其编码为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个回答



将此“JSON_HEX_APOS”添加到为我工作的json_encode函数</ p>

  $  jsonString = json_encode($ jsonEvent,JSON_HEX_APOS); 
</ code> </ pre>

干杯!</ p>
</ div>

展开原文

原文

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

 $jsonString = json_encode($jsonEvent, JSON_HEX_APOS);

cheers!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问