PHP print_r 只显示数组而不是纯文本

标签 php

我再次寻求帮助。

我找到了这个停用词脚本 - 我基本上从字符串中删除了所有常用词。

<?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...

关于PHP print_r 只显示数组而不是纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6234210/

相关文章:

php - 我的网站未在 SSL (HTTPS) 上加载

php - 在看到 Bootstrap 设计的更改之前需要先清除浏览器数据

当字段为空时,PHP 不返回任何行

php - "From:"电子邮件显示名称中的有效字符

php - 如何使用 php-curl 将文件上传到 "multipart"类型的 Google 云端硬盘?

php - 如何检查 id 是否已经存在 - codeigniter

php - 如何通过斜杠迁移来更新数据库中的数据?

php - .htaccess 网址 : rewrite missing css javascript and images file at local host Xampp

javascript - $_POST 在 ajax 表单提交中不起作用?

php - 获取上次查询中插入的记录/获取更改的行数(MySQL)