我正试图删除/过滤我数组中'位置'部分的杂散字符/单词。到目前为止,无论我做什么,这样做都会输出我不想要的字符。
字符我试图摆脱:picu00a0map
代码:$city = 'Kanosh';
$s = "SELECT * FROM `list` WHERE `city` LIKE '%".$city."%'";
$res = $mysqli->query($s) or trigger_error($mysqli->error."[$s]");
$a = array();
while($row = $res->fetch_array(MYSQLI_BOTH)) {
$a[] = array(
'title' => $row['title'],
'price' => $row['price'],
'rooms' => $row['rooms'],
'dimensions' => $row['dimensions'],
'location' => preg_replace('picu00a0map', '', $row['location']),
'price' => $row['price'],
'address' => $row['address'],
'seller' => $row['seller'],
'href' => $row['href'],
'date' => $row['date']
);
}
header('Content-Type: application/json');
echo json_encode($a);
$res->free();
$mysqli->close();
输出:[{"title":"Mobile Home Double Wide","price":"$85000","rooms":"3br","dimensions":"","location":"Kanosh UT picu00a0map","address":"","seller":"real estate - by owner","href":"http://saltlakecity.craigslist.org","date":"20140811214226"}, {"title":"Mobile Home Double Wide","price":"$85000","rooms":"3br","dimensions":"","location":"Kanosh UT picu00a0map","address":"","seller":"real estate - by owner","href":"http://saltlakecity.craigslist.org","date":"20140811223113"}]
请告知如何删除/过滤/替换数组元素中的字符和/或单词。
答案在这个线程中找到:
答案对于任何读到这篇文章的人,不要忘记解码unicode字符。