【问题标题】:Delete/Filter Characters and or Words from Element in Array从数组中的元素中删除/过滤字符和/或单词
【发布时间】:2014-08-19 01:10:53
【问题描述】:

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

我要删除的字符: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"}]

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

【问题讨论】:

标签: php mysql arrays json preg-replace


【解决方案1】:

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

Answer

对于阅读本文的任何人,不要忘记解码 unicode 字符。它把我吓跑了。

【讨论】:

    猜你喜欢
    • 2016-09-19
    • 2017-11-30
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2015-06-23
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多