Re: text conversion?
Posted: Tue Feb 27, 2024 1:47 pm
Here is a seriously frightening list of non-unicode font encodings:
https://philip.html5.org/data/charsets-2.html
https://philip.html5.org/data/charsets-2.html
Questions and answers about the LiveCode platform.
https://forums.livecode.com/
OK, I guessed, try this script, it will NOT doe the replace thing but encodes your exported text to UTF8 and chances are good
Code: Select all
on mouseUp
# set the itemdel to "/"
# get the effective filename of this stack
# delete item -1 of it
# put it & "/" into stakkensFilsti
## We can now use:
put specialfolderpath("resources") & "/" into stakkensFilsti
put stakkensFilsti & "xport af versemaal/" into dataMappensFilsti
put dataMappensFilsti & "versemaal.txt" into filensSti
put "file:" & filensSti into destFil
---det er den fil som enten skabes eller skrives til
put "versemålsnr,linjer,metrik,stavelser2" into meterListen
put "CSnr,KSnr,Hjsk19nr,Hjsk17nr,GTLnr,DDTnr,glDDSnr,nyDDSnr,vmliste,vers" into salmeListen
put "nyDDKnr,glDDKnr,andenMelBognr,prefNr,prefGlNr" into koralListen
put "" into tempResultat
--put tab into adskilningstegn
put "|" into adskilningstegn
set cursor to busy
set lockScreen to true
put the seconds into startTid
put "0" into antalKortBearbejdet
put "1" into linNumresultat
put the number of cards of this stack into tempSidsteSide
repeat with x = 2 to tempSidsteSide -------357 -----alle kortene!!!
go card x
put "" into tempTempResultat ---det midlertidige output (for dette kort!)
-------put "" into tempResultat ---det endelige output (for alle definerede kort!)
repeat with i = 1 to the number of lines in fld "vmliste"
set the itemDelimiter to ","
repeat with u = 1 to the number of items in meterListen
put fld (item u of meterListen) & adskilningstegn after line i of tempTempResultat
end repeat
set the itemDelimiter to ","
repeat with u = 1 to the number of items in salmeListen
if item u of salmeListen = "vmliste" then
--------- her skal lidt ekstrabehandling til
put line i of fld (item u of salmeListen) into afkortetLinje
delete word 1 to 2 of afkortetLinje
if char 1 of afkortetLinje = " " then
delete char 1 of afkortetLinje
end if
---get afkortetLinje
put afkortetLinje into tempAfkortet
if ";" is in tempAfkortet then
put char 1 to offset (";", tempAfkortet) - 1 of tempAfkortet into afkortetLinje
else if "(" is in tempAfkortet then
put char 1 to offset ("(", tempAfkortet) - 1 of tempAfkortet into afkortetLinje
else
put tempAfkortet into afkortetLinje
end if
replace tab with "" in afkortetLinje
put afkortetLinje & adskilningstegn after line i of tempTempResultat
---put erstatVanskeligeBogstaver(afkortetLinje) & adskilningstegn after line i of tempTempResultat
-----------
else
if line i of fld (item u of salmeListen) = "-" then
put "" & adskilningstegn after line i of tempTempResultat
else if line i of fld (item u of salmeListen) = "÷" then
put "" & adskilningstegn after line i of tempTempResultat
else if line i of fld (item u of salmeListen) = "" then
put "" & adskilningstegn after line i of tempTempResultat
else
put line i of fld (item u of salmeListen) & adskilningstegn after line i of tempTempResultat
end if
end if
end repeat
set the itemDelimiter to ","
repeat with u = 1 to the number of items in koralListen
put "" into koralPræfiks
put item u of koralListen into aktuelKoralbog
if aktuelKoralbog = "nyDDKnr" then
put "K " into koralPræfiks
else if aktuelKoralbog = "glDDKnr" then
put "gK " into koralPræfiks
end if
if line i of fld (item u of koralListen) = "-" then
put "" & adskilningstegn after line i of tempTempResultat
else if line i of fld (item u of koralListen) = "÷" then
put "" & adskilningstegn after line i of tempTempResultat
else if line i of fld (item u of koralListen) = "" then
put "" & adskilningstegn after line i of tempTempResultat
else
put line i of fld (item u of koralListen) into tempKoralLinje
put "," & koralPræfiks into kommaPræfiks
replace "," with kommaPræfiks in tempKoralLinje
put koralPræfiks & tempKoralLinje & adskilningstegn after line i of tempTempResultat
end if
end repeat
put adskilningstegn after line i of tempTempResultat
put "jabadaba" after line i of tempTempResultat
replace tab with "" in tempTempResultat
end repeat
------put return & tempTempResultat after url destFil
---put the number of lines of tempResultal into linNumresultat
---add 1 to linNumresultat
put tempTempResultat & return after tempResultat
---put tempTempResultat into line linNumresultat of tempResultat
---put the number of lines of tempResultal into linNumresultat
---add 1 to linNumresultat
add 1 to antalKortBearbejdet
end repeat ---- rep-loop for alle kortene!!
--put uniEncode(tempResultat) into url destFil
##########################################################
## DO NOT the REPLACE thing below. but put the TEXTENCODED text directly into that target file here:
put textencode(tempResultat,"UTF-8") into url(stakkensFilsti)
##
EXIT TO TOP
###########################################################
set lockScreen to false
end mouseUpThe font should not be a problem, but the font layout may be.When the webpage (PHP script) reads the text-file, no font is specified
Code: Select all
--little translator - otherwise some chars are not shown right in the web-page!!!!
repeat with i = 1 to the number of chars in tempResultat
put char i of tempResultat into tChar
if tChar = "§" then
put "ß" into tChar
else if tChar = "å" then
put "Â" into tChar
else if tChar = "Å" then
put "≈" into tChar
else if tChar = "æ" then
put "Ê" into tChar
else if tChar = "ø" then
put "¯" into tChar
else if tChar = "Æ" then
put "∆" into tChar
else if tChar = "Ø" then
put "ÿ" into tChar
else if tChar = "é" then
put "È" into tChar
else if tChar = "á" then
put "·" into tChar
else if tChar = "È" then
put "»" into tChar
else if tChar = "À" then
put "¿" into tChar
else if tChar = "ú" then
put "˙" into tChar
else if tChar = "Ù" then
put "Ÿ" into tChar
else if tChar = "Ü" then
put "‹" into tChar
else if tChar = "ö" then
put "ˆ" into tChar
else if tChar = "ü" then
put "¸" into tChar
else if tChar = "ä" then
put "‰" into tChar
end if
put tChar after tempResultat2
end repeat
put tempResultat2 into url destFilCode: Select all
$titel[] = utf8_encode($linjeArray[12]);Maybe that is a little part of the problem?joeMich wrote: Tue Feb 27, 2024 11:12 pm From the webpage I import/read the file as an array (through PHP).
Most of the material is numbers. But I had to do something with the title-part of the array.
Here I didI must admit that I don't understand itCode: Select all
$titel[] = utf8_encode($linjeArray[12]);
No it doesn't!
Code: Select all
...
## Collect your data...
## And convert to PHP friendly encoding:
put mactoiso(tempResultat) into url(stakkensFilsti)
...YepMaybe that is a little part of the problem?
Code: Select all
$titel[] = mb_convert_encoding($linjeArray[12],'UTF-8','ISO-8859-1');