PHP code to format Program Name for 1-click zune subscription
I added the Zune 1-click subscription option to the RawVoice properties at www.blubrry.com and www.techpodcasts.com. 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.
<a href=”< ?php
$title_for_zune = ereg_replace(‘[^A-Za-z0-9 ]’, ”, $show_title);
$title_for_zune = str_replace(‘ ‘, ‘_’, $title_for_zune);
?>” 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.