![](/img/trans.png)
[英]How to add the content of a text file into a mySQL database,the file content is given
[英]how to replace text in a mysql database content array
我正在尝试摆脱数据库内容中不必要的文本。我的代码如下所示:
if(mysql_num_rows($result))
$items[] = array();
while($row = mysql_fetch_assoc($result)) {
$items[] = array('id' => $row['id'], 'cat' => $row['cat'], 'type' => $row['type'], 'name' => $row['name'], 'sub_title' => $row['sub_title'], 'display_date' => $row['display_date'], 'slug' => $row['slug'], 'ticket_url' => $row['ticket_url'], 'status' => $row['status'], 'content' => $row['content'], 'display_until' => $row['display_until'], 'photo' => $row['photo'], 'thumb' => $row['thumb']);
$removals = array('\n','\r','\t','<\/div>\r\n');
$spaces = "";
$parsedText = str_replace($removals, $spaces, $items);
}
echo json_encode(array('events'=>$items));
然后内容显示如下:
{“ events”:[[],{“ id”:“ 66”,“ cat”:“ 9”,“ type”:“ 2”,“ name”:“Oileán-Blasket Islands庆祝活动”,“ sub_title“:”国家民俗剧院“,” display_date“:” 5月4日至5月6日,星期四,8.30pm“,” slug“:”此作品庆祝了过去时代在Blasket群岛上的生活,探索了岛民的生活方式“,” ticket_url“:”“,”状态“和”生存精神“,奥利昂(O'eánán)捕捉了这个岛屿社区的精髓,他们的传统和习俗,丰富的歌曲和故事,对生活的热爱以及彼此之间的亲密血缘。 “:” 1“,”内容“:” \\ r \\ n \\ t由爱尔兰国家民俗剧院成员主持</ strong>,该作品既庆祝并探索了布拉斯科特岛的生活,同时也挑战了我们自己的当代身份观念</ div> \\ r \\ n \\ r \\ n \\ t </ div> \\ r \\ n \\ r \\ n \\ tOileán</ strong> </ em>成立于2003年,庆祝成立50周年布拉斯凯特岛民离开大陆的旅程大布拉斯凯特岛位于沿海 对于来自爱尔兰和国外的许多人来说,西凯里岛仍然具有几乎神秘的意义。 这次拍摄展示了岛民的生活方式和生存精神,充分体现了该岛社区的精髓,他们的传统和习俗,丰富的歌曲和故事,对生活的热爱以及彼此之间的亲密血缘。 </ div> \\ r \\ n \\ r \\ n \\ t </ div> \\ r \\ n \\ r \\ n \\tOileán</ i> </ b>以独特的暹罗风格通过舞蹈,哑剧形式传播,音乐和歌曲。</ div> \\ r \\ n \\ r \\ n \\ t </ div> \\ r \\ n \\ r \\ n \\ t \\ r \\ n \\ t \\ t </ div> \\ r \\ n \\ t \\ r \\ n \\ t \\ t请注意,由于国家民俗剧院的表演很受欢迎</ strong>,某些作品可能会提前售罄,并且可能无法在线购买门票。 但是,我们经常会有退货,门票可能会在演出当天附近提供</ strong>。 请直接通过电话与我们联系:+353(0)66 7123055。</ em> </ div> \\ r \\ n \\ t \\ r \\ n \\ t \\ t </ div> \\ r \\ n \\ t \\ r \\ n \\ t \\ t </ div> \\ r \\ n </ div> \\ r \\ n“,” display_until“:” 20100504“,”照片“:” 1269869378-oilean_side.jpg“,”拇指“:” 1269869378 -oilean_thumb.jpg“},
上面的显示是数据库中的第一项。 我正在尝试替换上述内容中的所有\\ r,\\ n等?我该如何解决?我已经准备好了吗?
2件事
if(mysql_num_rows($result))
$items = array(); // not $items[], that would set the first item as an array
while($row = mysql_fetch_assoc($result)) {
$removals = array("\n","\r","\t","<\/div>\r\n");
$spaces = "";
$items[] = array(
'id' => $row['id'],
'cat' => $row['cat'],
'type' => $row['type'],
'name' => $row['name'],
'sub_title' => $row['sub_title'],
'display_date' => $row['display_date'],
'slug' => $row['slug'],
'ticket_url' => $row['ticket_url'],
'status' => $row['status'],
// replace the content here
// youll want to use preg_replace though otherwise youll end up with multiple </div>'s
'content' => str_replace( $removals, $spaces, $row['content'] ),
'display_until' => $row['display_until'],
'photo' => $row['photo'],
'thumb' => $row['thumb']
);
}
echo json_encode(array('events'=>$items));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.