Hack Forums
[PHP] Font encoding issue - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Font encoding issue (/showthread.php?tid=5539135)



Font encoding issue - Specs - Jan 31, 2017

Hi, so what im trying to do is create a very simple text converter. I plan to have a whole array of different character sets and then convert normal input into any one of them at random.

My problem is when im taking a character from the desired font, i assume the encoding is getting messed up and returning either a weird symbol or just a ?. I've tried various encoding functions but still no luck. If i just print out $font it displays as it should but it seems when i take a single character from the set, it starts to mess up.

Code: http://pastebin.com/3CS6TKXA

My current idea is to take the position from the normal font and use that position to get the matching character from the new font. I'm not sure if that's the best way, but it seems to get the job done.

Thanks!😁


* - Specs - Jan 31, 2017

(Jan 31, 2017 11:22 AM)Yani Wrote:  I think you should learn a bit more about this stuff because to me it seems that you're mixing everything up. Encodings, characters sets and fonts are all different things. If you're doing what I think you're doing you don't even need to think about "Fonts".

I know. I have the "font" in my function but as soon as i take a character from the string, it doesn't get displayed how it should. But if i print the string untouched, it works fine.


I managed to get this fixed by changing my approach to it. I decided to use an array for each character, its a little lengthier, but works great. Here's the code if anyone wants it: http://pastebin.com/LekRdWiU

You may want to add some checks for other symbols or whatever if you decide to ever use it.


* - Ryuga - Jan 31, 2017

Try this ..



* - Specs - Jan 31, 2017

(Jan 31, 2017 04:01 PM)Ryuga Wrote:  Try this ..

Thank you, this works great. Do you mind explaining where you got the "~~u" from? I know its a pattern, but im clueless as to where i would come up with that.


* - Ryuga - Jan 31, 2017

Actually, I got this from http://php.net/manual/en/function.mb-split.php#117588 - but from my understanding.. The tildes are delimeters and the 'u' modifier is there just to make preg_split know that $input is gonna be a UTF-8 encoded string (expect multibyte chars) .. 🎉