我有一个php文件,它读取一个csv文件并将其输出到数组。我无法删除csv文件中的“
p>”标签。输出总是在标签处中断我的数组。
如何显示
p>标签?
我的PHP代码:
$csv = array();
$lines = file('mycsv.csv', FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value) {
$csv[$key] = str_getcsv($value);
}
echo '<pre>';
print_r($csv);
echo '</pre>';
我的输出就像:
>
> [1] => Array
> (
> [0] => 123
> [1] => my_friend
> [2] =>
> [3] =>
> [4] => 100
> [5] => testtesttest
> [6] =>
> [7] =>
>
> here my array breaks
>
> )
>
> [2] => Array
> (
> [0] =>
>
> and continue here
> [1] => this is really bad
我想要这样:
>
> [1] => Array
> (
> [0] => 123
> [1] => my_friend
> [2] =>
> [3] =>
> [4] => 100
> [5] => testtesttest
> [6] =>
> [7] => here my array breaks and continue here this is really bad
FILE_IGNORE_NEW_LINES
Omit newline at the end of each array element
所以您的输出符合预期,因为中间有换行符。
如果要删除每个条目内的换行符,请使用诸如str_replace之类的字符来删除它们。也请看一下换行符。 \ r \ n。
foreach ($array as &$content) {
$content = htmlspecialchars($content);
}