我在 PHP 中从一个完美的文本文件中按字母顺序对数据进行排序,但不幸的是,自动填充的文本文件包含 #039 之类的字符;我想从最终结果中删除。尝试了很多方法来替换和删除字符,但没有成功。这是我到目前为止所拥有的:
<?php
error_reporting(E_ALL);
$fileName = 'cache/_city.txt';
$data = file_get_contents($fileName);
// Assuming that the file had the data in one line...
// Split the data using the delimiter
$split = explode("|", $data);
// Sort
sort($split);
// Put it all back together
$data = implode(" ", $split);
$data = str_replace("'" , "", $data);
echo $data;
?>
如何从 $data 中删除这段文本:#039;
样本数据 :
<a href="?city=Leiden">Leiden</a>|
<a href="?city=Papendrecht">Papendrecht</a>|
<a href="?city=Helmond">Helmond</a>|
<a href="?city=%26%23039%3Bs-Hertogenbosch">&#039;s-Hertogenbosch</a>|
<a href="?city=Hengelo">Hengelo</a>|
<a href="?city=Marknesse">Marknesse</a>|
<a href="?city=Wanssum">Wanssum</a>|
<a href="?city=Rijswijk">Rijswijk</a>|
<a href="?city=Leunen">Leunen</a>|
<a href="?city=Genemuiden">Genemuiden</a>|