68k-news icon indicating copy to clipboard operation
68k-news copied to clipboard

[French] Accented characters

Open sJARB opened this issue 3 years ago • 0 comments
trafficstars

Hi there ! I'm using Internet Explorer 3.0 integrated by Windows 95 OSR2, but i've problems displaying Accented characters in your french articles, beacause of unsupport of UTF-8.

Screenshot -> 20220312-170630-256256 Article URL -> https://68k.news/article.php?loc=FR&a=https://news.google.com/__i/rss/rd/articles/CBMi1wFodHRwczovL3d3dy5sZW1vbmRlLmZyL2VsZWN0aW9uLXByZXNpZGVudGllbGxlLTIwMjIvYXJ0aWNsZS8yMDIyLzAzLzEyL2d1ZXJyZS1lbi11a3JhaW5lLXBvdXItbmF0aGFsaWUtYXJ0aGF1ZC1sYS1jb25mcm9udGF0aW9uLWVudHJlLW1vc2NvdS1ldC1sZS1jYW1wLWltcGVyaWFsaXN0ZS1lc3QtdW5lLWd1ZXJyZS1lbnRyZS1icmlnYW5kc182MTE3MjM4XzYwNTkwMTAuaHRtbNIBAA?oc=5

I propose to you a PHP function that convert most common UTF-8 accented characters by html entities :

/**
  * @param string The string when you want to convert UTF-8 accented characters to HTML Entities (i.e. Only the article, or the entire page)
  * @return string The converted string with HTML Entities
  */
function accent(string $s) : string
{
	// Temporlary string
	$str = $s;
	
	// An array contains the most common accented characters (others can be add, be carefull the order of these one)
	$accents = array(
		"À","Â","Ä","Ç",
		"È","É","Ê","Ë",
		"Ì","Î","Ï","Ò",
		"Ô","Ö","Œ","Ù",
		"Û","Ü","à","â",
		"ä","ç","è","é",
		"ê","ë","ì","î",
		"ï","ò","ô","ö",
		"œ","ù","û","ü"
	);
	
	// An other array contains the same accented characters in HTML Entites equivalent (others can be add, be carefull the order of these one)
	$entites = array(
		"À","Â","Ä","Ç",
		"È","É","Ê","Ë",
		"Ì","Î","Ï","Ò",
		"Ô","Ö","Œ","Ù",
		"Û","Ü","à","â",
		"ä","ç","è","é",
		"ê","ë","ì","î",
		"ï","ò","ô","ö",
		"œ","ù","û","ü"
	);
	
	// The function to replace all of occurences of an accented characters by his HTML Entity equivalent
	$str = str_replace($accents,$entites,$str);
	
	// The return converted string
	return $str;
}

sJARB avatar Mar 12 '22 16:03 sJARB