ultrus Posted January 21, 2011 Share Posted January 21, 2011 Hello, I created an XML file to import into an InDesign XML workflow. InDesign is tripping on it though as it doesn't like importing characters like 'ö', nor does it like to import the xml entity name of 'ö'. It does however enjoy importing the entity number of 'ö'. How do I clean up a string to make this work using PHP? Here's what I have so far that doesn't seem to be doing anything yet that I can see (maybe my browser is converting it before I see the results?): <?php $foreignString = 'Dr. Wörner'; //This is what I want: Dr. W [&]#246;rner - take out brackets, forums are doing something odd with örner //This is what I DON'T want: Dr. Wörner //This is what I DON'T want: Dr. Wörner //referenced from http://www.lazycat.org/php-convert-entities.php $cleanString = htmlspecialchars( html_entity_decode($foreignString, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8' ); print $cleanString; ?> Am I on the right track? Any thoughts on how to finalize? Best regards, Chris Link to comment https://forums.phpfreaks.com/topic/225265-get-entity-numbers-not-names-for-unique-characters-like-%C3%B6-for-xml-document/ Share on other sites More sharing options...
ultrus Posted January 24, 2011 Author Share Posted January 24, 2011 No dice? I'm starting to rev up the Google engine on this one again today. I'll post if I find something, but feedback is welcome if you have thoughts. Plan B: I could make my own string replace function based on this table: http://www.w3schools.com/tags/ref_entities.asp Link to comment https://forums.phpfreaks.com/topic/225265-get-entity-numbers-not-names-for-unique-characters-like-%C3%B6-for-xml-document/#findComment-1164408 Share on other sites More sharing options...
litebearer Posted January 24, 2011 Share Posted January 24, 2011 perhaps this may guide you ... http://php.net/manual/en/function.ord.php Link to comment https://forums.phpfreaks.com/topic/225265-get-entity-numbers-not-names-for-unique-characters-like-%C3%B6-for-xml-document/#findComment-1164450 Share on other sites More sharing options...
ultrus Posted January 24, 2011 Author Share Posted January 24, 2011 Yeah I was mulling around there for a while. What I ended up doing that worked this morning is something like this: function replaceEntities($string) { $string = htmlentities($string); $string = str_replace( array( """, "'", "..."), array( "[&]#34;", "[&]#39;", "..."), //minus the brackets $string); return $string; } Worked great for what I needed. Thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/225265-get-entity-numbers-not-names-for-unique-characters-like-%C3%B6-for-xml-document/#findComment-1164521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.