{"id":6311,"date":"2014-05-04T05:07:15","date_gmt":"2014-05-03T19:07:15","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=6311"},"modified":"2014-05-04T05:07:15","modified_gmt":"2014-05-03T19:07:15","slug":"html-entities-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/html-entities-primer-tutorial\/","title":{"rendered":"HTML Entities Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/HTMLEntities.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"HTML Entities Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/HTMLEntities.jpg\" title=\"HTML Entities Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML Entities Primer Tutorial<\/p><\/div>\n<p>As a programmer, when you deal with <a target=_blank title='Database here at this blog' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=47'>database<\/a> issues and <a target=_blank title='CSV here at this blog' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=CSV'>CSV<\/a> you often come up with issues where you construct <a target=_blank title='CSV here at this blog' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=HTML'>HTML<\/a> or read HTML as part of the final solution, and you have to deal with the ambiguity of &#8216; and , characters, respectively, having dual purposes.    The &#8216; delimits characters in SQL for the databases MySql, MS-SQL, Oracle, Access and others.   The , character is the default delimiter for CSV data and lists of things that you <a target=_blank title='Javascript split' href='http:\/\/www.w3schools.com\/jsref\/jsref_split.asp'>&#8220;split&#8221;<\/a> or <a target=_blank title='PHP explode' href='http:\/\/au2.php.net\/explode'>&#8220;explode&#8221;<\/a> into an array.   But this can be problematic, in that &#8216; and , can also naturally exist in a person&#8217;s name, or their address, for instance.<\/p>\n<p>This is the situation where HTML entities can be very useful, as they can replace your delimiters (&#8216; and , are just two examples, but the method can apply to others as well) with what is known as HTML entities, to avoid any data confusion for the use of this data by Javascript and\/or PHP or any other client\/server-side language combinations you are using.<\/p>\n<p>Let&#8217;s take a look at <a target=_blank title='HTML Enties (list from Wikipedia)' href='http:\/\/en.wikipedia.org\/wiki\/List_of_XML_and_HTML_character_entity_references'>Wikipedia&#8217;s<\/a> write up regarding HTML entities.<\/p>\n<blockquote>\n<p>In SGML, HTML and XML documents, the logical constructs known as character data and attribute values consist of sequences of characters, in which each character can manifest directly (representing itself), or can be represented by a series of characters called a character reference, of which there are two types: a numeric character reference and a character entity reference. This article lists the character entity references that are valid in HTML and XML documents.<\/p>\n<p>Although in popular usage character references are often called &#8220;entity references&#8221; or even &#8220;entities&#8221;, this usage is wrong.[citation needed] A character reference is a reference to a character, not to an entity. Entity reference refers to the content of a named entity. An entity declaration is created by using the <!ENTITY name \"value\"> syntax in a document type definition (DTD) or XML schema. Then, the name defined in the entity declaration is subsequently used in the XML. When used in the XML, it is called an entity reference.\n<\/p>\n<\/blockquote>\n<p>Now let&#8217;s see a good link listing a lot of the HTML entities of use <a target=_blank title='HTML Entities' href='http:\/\/www.htmlhelp.com\/reference\/html40\/entities\/special.html'>here<\/a>.<\/p>\n<p>As the programmer confronted with such issues Javascript&#8217;s <a target=_blank title='Javascript replace' href='http:\/\/www.w3schools.com\/jsref\/jsref_replace.asp?utm_source=twitterfeed&#038;utm_medium=twitter'>replace<\/a> and PHP&#8217;s <a target=_blank title='PHP str_replace' href='http:\/\/au2.php.net\/str_replace'>str_replace<\/a> come in really handy.<\/p>\n<p>Example code snippets are shown below:<\/p>\n<ul>\n<li><code>str_replace(\"'\", \"&amp;rsquo;\", $myPHPvar);<\/code>   \/\/ replace all &#8216; with its HTML entity in PHP<\/li>\n<li><code>str_replace(\"&amp;#44;\", \",\",  $myPHPvar); <\/code>  \/\/ replace all HTML entity occurrences back to , in PHP<\/li>\n<li><code>myJavascriptVar.replace(\/,\/g, \"&amp;#44;\"); <\/code>  \/\/ replace all , with its HTML entity in Javascript<\/li>\n<li><code>myJavascriptVar.replace(\/&amp;rsquo;\/g, \"'\");<\/code>   \/\/ replace all HTML entity occurrences back to the original &#8216; character in Javascript<\/li>\n<\/ul>\n<p>Of course, this is like a &#8220;first principles&#8221; talk above, but, as you can imagine with such a fundamental subject, the languages have catered well for the thousands of other ways &#8220;to skin a cat&#8221; &#8230; meeeeeeeeeeeeoooooooowwwwww! &#8230; sorry, kitty &#8230; and we&#8217;ll leave you with some good links here &#8230; so, chou for now &#8230; tee, hee &#8230;<\/p>\n<ul>\n<li><a target=_blank title='PHP HTML entities advice' href='http:\/\/au1.php.net\/htmlentities'>PHP HTML entities advice<\/a><\/li>\n<li><a target=_blank title='Javascript HTML entities advice' href='http:\/\/css-tricks.com\/snippets\/javascript\/htmlentities-for-javascript\/'>Javascript HTML entities advice<\/a><\/li>\n<\/ul>\n<p> || chortle, chortle.<\/p>\n<p>Here is a Yahoo Answers question regarding this topic area &#8230; <a target=_blank title='What is &amp;raquo used when coding?' href='http:\/\/au.answers.yahoo.com\/question\/index?qid=20140223084924AACjYhD'>What is &amp;raquo used when coding?<\/a><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d6311' onclick='var dv=document.getElementById(\"d6311\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=HTML\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d6311' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As a programmer, when you deal with database issues and CSV you often come up with issues where you construct HTML or read HTML as part of the final solution, and you have to deal with the ambiguity of &#8216; &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/html-entities-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,37],"tags":[103,283,299,576,577,652,932,997,1319],"class_list":["post-6311","post","type-post","status-publish","format-standard","hentry","category-database","category-elearning","category-tutorials","tag-array","tag-csv","tag-database-2","tag-html","tag-html-entities","tag-javascript","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/6311"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=6311"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/6311\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=6311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=6311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=6311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}