从数组中的元素中删除/过滤字符和/或单词

时间:2014-08-19 01:10:54

标签: php mysql arrays json preg-replace

我正在尝试删除/过滤“位置”中的流浪字符/字词。我的数组中的部分。到目前为止,无论我做什么,这样做都会输出我不想要的角色。

我想摆脱的角色:pic \ u00a0map

代码:

$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('pic\u00a0map', '', $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     pic\u00a0map","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      pic\u00a0map","address":"","seller":"real estate - by     owner","href":"http:\/\/saltlakecity.craigslist.org","date":"20140811223113"}]

请告知如何删除/过滤/替换数组元素内的字符和/或单词。

1 个答案:

答案 0 :(得分:0)

在这个帖子中找到了答案:

Answer

对于阅读此内容的任何人,请不要忘记解码unicode字符。它让我失望。