php preg_split 无法识别空格 [英] php preg_split doesn't recognise spaces

查看:54
本文介绍了php preg_split 无法识别空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我复制&粘贴 Betfair 的足球比赛,例如伯恩茅斯 v 托特纳姆",这是存储在 MySQL 数据库中.但是,当我尝试:

I copy & paste football games from Betfair e.g. "Bournemouth v Tottenham" and this is stored in a MySQL database. However, when I try:

preg_split('/\s+/',  $row['match']);

正如之前在这里所建议的那样,它不会在第一个空间上拆分(我的最终目标是类似于'/\s[v]\s/').当我手动将数据库中的字段覆盖为"v "时,它会正确拆分它.在浏览器和 PHPMyAdmin 中都显示为空格但未解析为空格时,它会如何处理这个字符?我试过  但没有运气.一个示例字符串是:

As suggested on here previously it doesn't split on the first space (my ultimate goal would be something like'/\s[v]\s/'). When I manually overwrite the field in the database as " v " it then splits it correctly. What could it be treating this character as that appears as a space both in the browser and in PHPMyAdmin but doesn't parse as one? I've tried   but no luck. An example string is:

巴塞罗那对阵曼城 - 周三 19:45

Barcelona v Man City - Wednesday 19:45

使用此解析:http://pasteall.org/pic/show.php?id=107841在Man City"空间而不是v"之前,它不会拆分字符串.第一个有效,因为我手动用数据库中的空格替换了问题字符

with this parsing: http://pasteall.org/pic/show.php?id=107841 It doesn't split string until the "Man City" space rather than the " v ". The first one works as I manually replaced the problem chars with spaces in the database

推荐答案

虽然当 PHP 询问时数据库说的是 UTF8 字符集,但它说的是 latin1.解决方案是:

Although the database says UTF8 characterset when PHP asks it says latin1. Solution was:

mysqli_set_charset($dbc, "utf8");

这篇关于php preg_split 无法识别空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆