Handling apostrophes when generating HTML with PHP

前端 未结 5 770
慢半拍i
慢半拍i 2020-12-22 02:13

I am generating radio buttons based on an XML config values. Sometimes they have apostrophes in the text. When manipulating this data in PHP, I seem to lose everything after

5条回答
  •  独厮守ぢ
    2020-12-22 03:05

    I usually stick with those 2 easy options, both equally efficient:

    1. You can encapsulate one type of quotes in the other type

    $var = " here single quotes ' are encapsulated in double quotes";
    $var = 'here double quotes " are encapsulated in single quotes';

    1. you can escape quotes by using \

    $var = "just quote some mathematician: \"quot erat demonstrandum\".";

提交回复
热议问题