Columbus, Ohio

PHP code to format Program Name for 1-click zune subscription

I added the Zune 1-click subscription option to Blubrry Podcasting and Tech Podcasts. I ran into an issue where show titles that contain special characters, such as quotes, would break the rest of the web page.

Below is the solution I implemented for the problem.

Fix

<a href=”< ?php
$title_for_zune = ereg_replace(‘[^A-Za-z0-9 ]’, ”, $show_title);
$title_for_zune = str_replace(‘ ‘, ‘_’, $title_for_zune);
echo ‘zune://subscribe/?’.$title_for_zune.’=’.$feed;
?>” title=”Add to Zune”>Add to Zune</a>

Having spaces in the URL does not validate, so I replace spaces with the _ character. If you are not worried about HTML validation, you can remove the str_replace function call.

I am not sure who came up with this protocol for the add to Zune 1-click subscription, as it does not appear to be very well thought out. Most other sites like Digg only require the feed url, which will never contain characters that could break your web pages.  As Jason Van Orden points out, the format is more complex than it needs to be.

One Response

Comments are closed.

Join My FREE Newsletter

Get the latest news and episodes of the Cloud Entrepreneur Podcast and Angelo’s development blog directly in your inbox!