mardi 21 juin 2016

Encoding Issues : iTunes XML

I'm having an issue with some HTML ascii codes showing up in our podcast descriptions on iTunes. Unfortunately i'm not great with PHP, but am trying anyway! I've found a section that I believe deals with replacing or stripping codes....

// iTunes summary does not allow any HTML and must be shorter than 4000 characters
$itunes_summary = strip_tags( get_the_content() );
$itunes_summary = str_replace( array( '&', '>', '<', ''', '"', '`' ), array( __( 'and', 'seriously-simple-podcasting' ), '', '', '', '', '' ), $itunes_summary );
$itunes_summary = mb_substr( $itunes_summary, 0, 3949 );

// iTunes short description does not allow any HTML and must be shorter than 4000 characters
$itunes_excerpt = strip_tags( strip_shortcodes( get_the_excerpt() ) );
$itunes_excerpt = str_replace( array( '&', '>', '<', ''', '"', '`', '[andhellip;]', '[&hellip;]' ), array( 'and', '', '', '', '', '', '', '' ), $itunes_excerpt );
$itunes_excerpt = mb_substr( $itunes_excerpt, 0, 224 );

But it doesn't seem like it's working because the output looks like this...

<description>
<![CDATA[
Post Father&#8217;s Day tea time on the DahlCast &#8211; What&#8217;s your fav? Lipton, Snapple or handle bar mustaches? Pet peeves raid today&#8217;s show as the guys talk flip flops, situational unawareness and open table plus the internet&#8217;s latest craze the Cheerio Challenge.
]]>
</description>
<itunes:subtitle>
<![CDATA[
Post Fatherand#8217;s Day tea time on the DahlCast and#8211; Whatand#8217;s your fav? Lipton, Snapple or handle bar mustaches? Pet peeves raid todayand#8217;s show as the guys talk flip flops, situational unawareness and open table plus the internetand#8
]]>
</itunes:subtitle>
<content:encoded>
<![CDATA[
<p>Post Father&#8217;s Day tea time on the DahlCast &#8211; What&#8217;s your fav? Lipton, Snapple or handle bar mustaches? Pet peeves raid today&#8217;s show as the guys talk flip flops, situational unawareness and open table plus the internet&#8217;s latest craze the Cheerio Challenge.</p>
]]>
</content:encoded>
<itunes:summary>
<![CDATA[
Post Father's Day tea time on the DahlCast &#8211; What's your fav? Lipton, Snapple or handle bar mustaches? Pet peeves raid today's show as the guys talk flip flops, situational unawareness and open table plus the internet's latest craze the Cheerio Challenge.
]]>
</itunes:summary>

As you can see... sometimes the apostrophe works... other times it doesn't. Strange...

If it's helpful, here's where the item is built...

<item>
        <title><?php esc_html( the_title_rss() ); ?></title>
        <link><?php esc_url( the_permalink_rss() ); ?></link>
        <pubDate><?php echo esc_html( mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ) ); ?></pubDate>
        <dc:creator><?php echo $author; ?></dc:creator>
        <guid isPermaLink="false"><?php esc_html( the_guid() ); ?></guid>
        <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
        <itunes:subtitle><?php echo $itunes_excerpt; ?></itunes:subtitle>
        <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
        <itunes:summary><?php echo $itunes_summary; ?></itunes:summary><?php if ( $episode_image ) { ?>
        <itunes:image href="<?php echo esc_url( $episode_image ); ?>"></itunes:image><?php } ?>
        <enclosure url="<?php echo esc_url( $enclosure ); ?>" length="<?php echo esc_attr( $size ); ?>" type="<?php echo esc_attr( $mime_type ); ?>"></enclosure>
        <itunes:explicit><?php echo esc_html( $explicit_flag ); ?></itunes:explicit>
        <itunes:block><?php echo esc_html( $block_flag ); ?></itunes:block>
        <itunes:duration><?php echo esc_html( $duration ); ?></itunes:duration>
        <itunes:author><?php echo $author; ?></itunes:author>
</item>

Thank you so much for your time and consideration!

Aucun commentaire:

Enregistrer un commentaire