php preg_split doesn't recognise spaces

孤者浪人 提交于 2019-12-11 05:28:31

问题


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']);

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:

Barcelona v Man City - Wednesday 19:45

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


回答1:


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

mysqli_set_charset($dbc, "utf8");


来源:https://stackoverflow.com/questions/40131233/php-preg-split-doesnt-recognise-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!