I am working with Del.icio.us tags in a PHP script. Have the script functioning as I would like it to.
Now I need to work on an array I build in the script where a variable to limit the number of tags we actually ultimately display is imposed upon the array.
For example: if my array ($tags) has 242 elements in it I want just the first number of them as defined by the variable ($limit). Now the tricky part is... IF the number of elements (count($tags);) is greater than the limit then we delete the elements from the array after that number.
E.G. If $limit = 25 then we would keep the first 25 array elements of the 242.
IF $limit =0 or count($tags) is less than $limit we process normally.
With this is mind here is the script:
Code: Select all
<?php
//Del.icio.us User Name
$userId = "del.ico.us user name";
//process the JS feed (TagRoll)
$url = "http://del.icio.us/feeds/js/tags/".$userId;
$read = file_get_contents($url);
//run the match and build the tags array
$match = '/"(.*?)":/';
preg_match_all($match, $read, $tags);
$tags = $tags[1];
//count of the number of elements in the tags array
$tagCount = count($tags);
//this is a temporary echo statement to check number of tags
//echo 'Tag Count is '.$tagCount.'<br />';
//process for output
echo '<LINK REL="StyleSheet" HREF="deltags.css" TYPE="text/css">';
echo'<div class="delicious-tags" id="delicious-tags-'.$userId.'"><ul class="delicious-cloud">TAGS: ';
foreach ($tags as $tag) {
echo '<li class="delicous-tags"><a href="http://del.icio.us/'.$userId.'/'.$tag.'">'.$tag.'</a></li>';
}
echo '</ul></div>';
?>The cutting the data from the tag is what I REALLY need to know how to do...
Thanks for your help in advance.
And again, advice welcome
Have a good day!
Mike