Jump to content

[SOLVED] converting to smart quotes: php to xml


kaplanyo

Recommended Posts

I've been doing some searching and reading about smart quotes, but I'm not sure how to invoke the function in my case. I'm using php/mysql to output some db content as xml that gets loaded in flash. I would like to run the conversion so that my xml gets the Entity Name instead of the keystroke, which in Flash just ends up blank. I saw a couple different approaches, but I'm still a rookie and can't figure out where to invoke the function to get my conversion. Any help would be very nice and greatly appreciated.

 

I've got some nice features going, like scrollwheel functionality and a a lovely embedded font, but the real quotes and apostrophes, either pasted from an outside word file or keystroked would be the cherry on top.

 

Here's what my Flash and XML output are looking like:

flash: http://www.sepiachicago.com/dev/wine.html

xml output using php/mysql: http://www.sepiachicago.com/winemenu_output_xml.php

 

Here's some of the code I'm working with in my output.

echo "<winesbyglass menu_name=\"WINES BY THE GLASS\">\n";
while ($rowGlass = mysql_fetch_assoc($resultGlass)) {
// you need to use the htmlentities to get the accented characters in flash.
// unfortunately, curly quotes are outside the set of entities that can be converted.
echo "\t<category category_name=\"".htmlentities($rowGlass['category'])."\">".htmlentities($rowGlass['menuitems'])."</category>\n";}
mysql_free_result($resultGlass);
echo "</winesbyglass>\n";

 

and I've seen, which looks like what I want to use, but I'm not sure where to invoke it during my xml outputting.

function get_html_translation_table_CP1252() {
    $trans = get_html_translation_table(HTML_ENTITIES);
    $trans[chr(130)] = '‚';    // Single Low-9 Quotation Mark
    $trans[chr(131)] = 'ƒ';    // Latin Small Letter F With Hook
    $trans[chr(132)] = '„';    // Double Low-9 Quotation Mark
    $trans[chr(133)] = '…';    // Horizontal Ellipsis
    $trans[chr(134)] = '†';    // Dagger
    $trans[chr(135)] = '‡';    // Double Dagger
    $trans[chr(136)] = 'ˆ';    // Modifier Letter Circumflex Accent
    $trans[chr(137)] = '‰';    // Per Mille Sign
    $trans[chr(138)] = 'Š';    // Latin Capital Letter S With Caron
    $trans[chr(139)] = '‹';    // Single Left-Pointing Angle Quotation Mark
    $trans[chr(140)] = 'Œ';    // Latin Capital Ligature OE
    $trans[chr(145)] = '‘';    // Left Single Quotation Mark
    $trans[chr(146)] = '’';    // Right Single Quotation Mark
    $trans[chr(147)] = '“';    // Left Double Quotation Mark
    $trans[chr(148)] = '”';    // Right Double Quotation Mark
    $trans[chr(149)] = '•';    // Bullet
    $trans[chr(150)] = '–';    // En Dash
    $trans[chr(151)] = '—';    // Em Dash
    $trans[chr(152)] = '˜';    // Small Tilde
    $trans[chr(153)] = '™';    // Trade Mark Sign
    $trans[chr(154)] = 'š';    // Latin Small Letter S With Caron
    $trans[chr(155)] = '›';    // Single Right-Pointing Angle Quotation Mark
    $trans[chr(156)] = 'œ';    // Latin Small Ligature OE
    $trans[chr(159)] = 'Ÿ';    // Latin Capital Letter Y With Diaeresis
    ksort($trans);
    return $trans;
}

Link to comment
Share on other sites

I figured it out. I used a function to run through and replace the odd key inputs. The quotes and apostrophes look great in the fancy winery names.

http://www.sepiachicago.com/dev/wine.html

 

function convert_smart_quotes($string) {  
    $search = array(chr(145),chr(146),chr(147),chr(148));       
    $replace = array("‘", "’", '“', '”');      
     return str_replace($search, $replace, $string);  
}  
// then in my loop
echo "<winesbyglass menu_name=\"WINES BY THE GLASS\">\n"; 
while ($rowGlass = mysql_fetch_assoc($resultGlass)) { 
// use the htmlentities to get the accented characters in flash.
// run the conversion function first for the characters that aren't covered in htmlentities
$convertRowGlass = convert_smart_quotes($rowGlass); 
echo "\t<category category_name=\"".htmlentities($rowGlass['category'])."\">".htmlentities($convertRowGlass['menuitems'])."</category>\n";} 
mysql_free_result($resultGlass); 
echo "</winesbyglass>\n";  

 

Part of my problem is I don't grasp the basics quick enough. I found this great page to learn about using php functions:

http://www.tizag.com/phpT/phpfunctions.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.