How to represent a unicode character in php source code

i’d like to do this:

str_replace( ‘\’', ‘’, $string );

where the red replace string is/should be a right single quote. how to include/represent that character in the above situation? with the above the right single quote gets mangled up (in the source code/text editor itself that is). so i tried:

str_replace( ‘\’', 0xE28099, $string );

as 0xE28099 is the right single quote in utf-8, but that didnt’ work. any ideas? thanks.

Make sure you save your files as ISO-8859-1, not Windows-1252.

it was set to “Western ISO Latin 1” – i’m using BBEdit on mac os x. i did set the source code encoding of the file itself to utf-8 at one point, at which point BBEdit automatically changed the HTML tag’s specification in the code.

which one are you suggesting should work once character encoding of file is sorted out?: ‘’’ or 0xE28099 ? presumably ‘’’ ? is there no way to specify a character constant with something like 0xE28099 ? (php 5 this is)

the utf-8 setting didn’t/doesn’t stick – it ends up going back to Western ISO Latin 1 in the upload and download (FTP) process regardless of the tag in the HTML (but bearing in mind it’s not a HTML doc so the HTML char encoding tag is not in the usual place it’s not surprising that tag isn’t having an effect).

if there were a way to specify character constant by value that would get round any character encoding issues connected with the encoding of the source file itself (i think) but i suspect there may not be a way to do that?

thanks.

just to add: when i include an actual right single quote mark character in the source code and select Western ISO Latin 1 as the encoding of the source file and then go to save, BBEdit says:

Unmappable character(s) detected.
This document contains one or more characters that could not be represented in the document’s encoding. You can save the document as UTF-8…

saving as UTF-8 is what i’ve already tried as said above. it seems to work, but then on download for editing the file returns to Western ISO Latin 1, and the right single quote mark is mangled in the source code. so maybe this is an FTP and/or server issue, and using UTF-8 is just fine – it’s a question of making it stick? maybe. (once downloaded for editing, and it reverts to Western ISO Latin 1, thus mangling the character in the source doe, changing the encoding back to ‘UTF-8 no BOM’ does not fix the mangled character[*] – it stays mangled). would all be a hell of a lot easier if i could just state the right single quote character as a value constant somehow. thanks.

.[*] maybe that doesn’t matter? maybe that mangled form is the constant representation i’m looking for? i’ll check that.

If it’s to be outputted to html, use html entities, I guess.

hi, i haven’t got a problem outputting it, i’ve got a problem representing it (a right single quote) in source code as a constant.

thanks.

try


str_replace( '\\'', "\\xE2\\x80\\x99", $string );

i don’t really want to change the whole document’s (which includes the HTML) encoding just because i want to state a right single quote in the php code. what about having the right single quote in a seperate file which just contains a right single quote and including it and assigning it to a variable somehow?

$rightsinglequote = include(‘right_single_quote_char_in_a_file.txt’); // not even sure if that’s legal php.

edit: ah, i posted this message before i saw your reply stereofrog. i will try your suggestion right now. thanks :slight_smile:

yes! that’s it :slight_smile: i knew there was a way like that, just didn’t know the details of it.

thanks very much.