(* i have an applescript that generates a PHP script which it writes as a string. applescript writes strings (when not unicode) as macroman encoded text, but php seems to expect windows-1252 encoding, so most non-ascii characters like ö, é and ® are interpreted incorrectly. i created this routine to write the characters as windows-1252. when converted, written, then opened on a mac, these characters won't look right (unless you specifically open as windows-1252 encoded text), but php should read them correctly. note: some characters in macroman do not have equivalents in Western (Windows Latin 1), so they will be replaced by character 149 which is the solid bullet character (•). if a different character is desired, replace 149 with the desired decimal character code in the "theConverts" list below, e.g. 20 for space *)


set theText to "Testing for Jörg! and Crü? Äll Çlear. ¡go! ©1998 ™Kraft 44°F •99 π=3.1415927"
set theText to text returned of (display dialog "re-encode what" default answer theText)
set theNewText to my convertText(theText)
display dialog theNewText default answer theNewText


on convertText(theText)
	--convert to windows encoding for php
	set theConverts to {196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229, 231, 233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244, 246, 245, 250, 249, 251, 252, 134, 176, 162, 163, 167, 149, 182, 223, 174, 169, 153, 180, 168, 149, 198, 216, 149, 177, 149, 149, 165, 181, 149, 149, 149, 149, 149, 170, 186, 149, 230, 248, 191, 161}
	set theTextX to ""
	repeat with eachLetter in theText
		set eachNum to ASCII number of eachLetter
		if eachNum > 127 and eachNum < 194 then
			set newNum to item (eachNum - 127) of theConverts
		else
			set newNum to eachNum
		end if
		set theTextX to theTextX & (ASCII character newNum)
	end repeat
	return theTextX
end convertText


-- applescript page

(*
html entitymacroman decimalwindows-1252 decimal
Ä128196
Å129197
Ç130199
É131201
Ñ132209
Ö133214
Ü134220
á135225
à136224
â137226
ä138228
ã139227
å140229
ç141231
é142233
è143232
ê144234
ë145235
í146237
ì147236
î148238
ï149239
ñ150241
ó151243
ò152242
ô153244
ö154246
õ155245
ú156250
ù157249
û158251
ü159252
160134
°161176
¢162162
£163163
§164167
165149
166182
ß167223
®168174
©169169
170153
´171180
¨172168
173none
Æ174198
Ø175216
176none
±177177
178none
179none
¥180165
µ181181
182none
183none
184none
π185none
186none
ª187170
º188186
Ω189none
æ190230
ø191248
¿192191
¡193161

*)