in reply to language Decoding problem..?

$titlenamefromindex=encode_entities($titlenamefromindex,"\200-\377");

The variable $titlenamefromindex is already entity-encoded, and now you're double-encoding it. Are you sure that's what you want?