如何解决PHP print_r仅显示数组而不是纯文本
| 我再次寻求帮助。 我发现了这个停用词脚本-我基本上从字符串中删除了所有常见词。<?php
$CommonWords = file_get_contents(\'http://localhost/stopwords.txt\');
$CommonWords = explode(\"\\n\",$CommonWords);
$CommonWords = array_map(\'trim\',$CommonWords); // <---- ADD THIS LINE
$keywords = \'The <meta> tag’s keyword attribute is not the page rank panacea it once was back in the prehistoric days of Internet search. It was abused far too much and lost most of its cachet. But there’s no need to ignore the tag. Take advantage of all legitimate opportunities to score keyword credit,even when the payoff is relatively low. Fill in this tag’s text with relevant keywords and phrases that describe that page’s content\';
$search_keywords = strtolower(trim($keywords));$arrWords = explode(\' \',$search_keywords);
$arrWords = array_unique($arrWords);
foreach ($arrWords as $word) {
if (!in_array($word,$CommonWords) && (trim($word) != \'\'))
{
$searchWords[] = $word;
}
}
print_r($searchWords);
?>
代码的输出如下所示:
Array ( [0] => [1] => tag’s [2] => keyword [3] => attribute [4] => page [5] => rank [6] => panacea [7] => prehistoric [8] => days [9] =>)
我如何格式化它,以便输出看起来像这样:(没有数组和数字)
tag\'s,attribute,page,rank,panacea,prehistoric,days
谢谢
解决方法
在结果数组上使用
implode()
。
$myString = implode( \',\',$myArray ); // Results in Item1,Item2,Item3,etc...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。