我们如何从任何 ORDER BY DECREASING 或 INCREASING 中获取独特的元素
下面给出的代码取自 stackoverflow.com!谁能告诉我如何通过减少或增加来获取数组元素的顺序!请帮助我!提前致谢
$contents = file_get_contents($htmlurl);
// Get rid of style, script etc
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<head>.*?</head>@siU', // Lose the head section
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$contents = preg_replace($search, '', $contents);
$result = array_count_values(
str_word_count(
strip_tags($contents), 1
)
);
print_r($result);
Code given below is taken from the stackoverflow.com !!! Can anyone tell me how to get the array elements order by decreaseing or increasing !! plz help me !!! Thanks in advance
$contents = file_get_contents($htmlurl);
// Get rid of style, script etc
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<head>.*?</head>@siU', // Lose the head section
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$contents = preg_replace($search, '', $contents);
$result = array_count_values(
str_word_count(
strip_tags($contents), 1
)
);
print_r($result);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要 PHP 的 sort 函数。我不会在这里重复手册。
You need PHP's sort function. I won't duplicate the manual here.
剥离标签后,您可以使用
str_word_count
获取字符串中使用的单词数组,然后使用array_count_values
获取单词的频率。现在,要根据频率对单词进行排序,您可以使用
asort
进行升序排列,或使用arsort
进行降序排列。查看
After stripping the tags, you get an array of words used in the string by using
str_word_count
next you are usingarray_count_values
to get the frequency of the words.Now to sort the words based on frequency you can use
asort
for ascending order orarsort
for descending order.See it