Skip to content

Instantly share code, notes, and snippets.

@tsrivishnu
Created September 15, 2012 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsrivishnu/3728793 to your computer and use it in GitHub Desktop.
Save tsrivishnu/3728793 to your computer and use it in GitHub Desktop.
displaying the unique tags in a XML RSS Feed using PHP
<?php
$url = $_GET['feed_url'];
ini_set( "display_errors", 0);
if(@$test = file_get_contents($url))
{
if($xml = simplexml_load_string($test))
{
$search = array('<', '>', 'red</font>&gt;');
$replace = array('&lt;<font color=red>', '</font>&gt;','red>');
$disp = str_replace($search, $replace, $test);
//echo "<pre>".$disp."</pre>";
$json=json_encode($xml);
$test_a=json_decode($json, true);
echo "<br><br>";
echo "Please check the tags of whose values you need as a update<br><br>";
processArray($test_a,"root");
echo "<input type='hidden' name='url_valid_flag' id='url_valid_flag' value='1'>
<br><input type='hidden' name='xml_string' id='xml_string' value='".$xml."'>"; //for form validation of check boxes of tags, 0 for invalid url, 1 for valid url
}
else if($test_a=json_decode($test, true))
{
//echo "Check the <a href='xml-display.php?url=$url' target='_blank'>xml</a> available for the $url <br><br>";
echo "Please check the tags of whose values you need as a update<br><br>";
processArray($test_a,"root");
echo "<input type='hidden' name='url_valid_flag' id='url_valid_flag' value='1'>
<br><input type='hidden' name='xml_string' id='xml_string' value='".$xml."'>"; //for form validation of check boxes of tags, 0 for invalid url, 1 for valid url
}
else
{
echo "<br><center><font color=red>Please enter a valid URL containing XML data</font><center>";
echo "<input type='hidden' name='url_valid_flag' id='url_valid_flag' value='0'>"; //for form validation of check boxes of tags, 0 for invalid url, 1 for valid url
}
}
else
{
echo "<br><center><font color=red>Please enter a valid URL</font><center>";
echo "<input type='hidden' name='url_valid_flag' id='url_valid_flag' value='0'>"; //for form validation of check boxes of tags, 0 for invalid url, 1 for valid url
}
function processArray($array,$parent_p) {
global $count;
$count++; //this variable is for calculating tab space
$parent=$parent_p;
if(is_array($array) === true)
{
foreach($array as $key => $value)
{
$parent_2=$parent_p;
if(is_array($value)==true && is_numeric($key)!=true) // for getting the parent node name properly.
{
$parent=$key;
}
if(is_array($value) === true)
{
if(is_numeric($key) != true) // for displaying the parent node, just for reference.
{
for($i = 1 ; $i < $count ; $i++) echo "&nbsp;&nbsp;"; //change this to space ' ' if running from CLI
echo "<font color='red'>".$key."</font><br/>";
}
$size=count($array);
if(is_numeric($key)== true) // for not displaying the duplicates.
{
for($j=0; $j<($size-1); $j++)
{
array_pop($array);
}
}
@processArray($array[$key],$parent);
}
else
{
for($i = 1 ; $i < $count ; $i++) echo "&nbsp;&nbsp;";
echo "<input type='checkbox' name='tags[]' id='tags' value=".$key."_".$parent_2.">".$key."<br />";
}
}
}
//echo "<font color=blue>".$parent_2."</font><br>";
$count--;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment