Skip to content

Instantly share code, notes, and snippets.

@deepak-rajpal
Last active September 14, 2015 12:16
Show Gist options
  • Save deepak-rajpal/55270d0f8a72542c9b35 to your computer and use it in GitHub Desktop.
Save deepak-rajpal/55270d0f8a72542c9b35 to your computer and use it in GitHub Desktop.
Converting space and slash into commas from URL variable and making a valid next URL
<?php
// For an current page/URL is: http://mysite.com/currency-pair-detail?fullname=US Dollar / Indonesian Rupiah FX Spot Rate
// Feed URL logic, first check from url keywords, then check url from shortcode else set default one.
if (isset($_REQUEST['fullname']) && $_REQUEST['fullname']!="") {
// create a feed url by finding keywords from current url (fullname variable)
$headlines_keywords = $_REQUEST['fullname'];
$headlines_keywords = strstr($headlines_keywords, 'FX Spot Rate', true);
$headlines_keywords = str_replace(" / ",",", $headlines_keywords);
$headlines_keywords = str_replace(" ","%2B", $headlines_keywords);
$feed_url = "http://headlines.com/?keywords=$headlines_keywords&firstRow=0&numRows=6";
} else if ($feed_url==""){
$feed_url = "http://headlines.com/API/?keywords=a,the,up,down,first,last,now&firstRow=0&numRows=6";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment