1

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

Dird
  • 39
  • 5
  • Try `preg_split('/\s+/u', $row['match']);`. Also, there may be other non-printable chars that may prevent the string from splitting. – Wiktor Stribiżew Oct 19 '16 at 12:20
  • Doesn't do anything different. How to find out the non-printables and accomodate for them? – Dird Oct 19 '16 at 12:36
  • Copy the value from the DB into http://r12a.github.io/apps/conversion/ Convert field, and click *Convert*. Check for wierd additional codes you get. – Wiktor Stribiżew Oct 19 '16 at 12:38
  • Nothing jumps out. UTF8 encoding of database spaces and hitting spacebar are the same...presumably my copy/paste motion fixes it – Dird Oct 19 '16 at 12:46
  • I clicked convert. They don't appear below in the UTF section etc until you do. I also clicked individual convert buttons below but still nothing appearing – Dird Oct 19 '16 at 12:48
  • Example string & parsing output added – Dird Oct 19 '16 at 12:54
  • Ok, I see it contains no weird characters. However, [this snippet](https://ideone.com/5dY95z) proves there is no issue. There must be something *before* this line of code that modifies it, or the string does not really look like you showed. – Wiktor Stribiżew Oct 19 '16 at 13:06
  • OK. HEX() shows "a v Man C" in the database rather than "a v Man C" – Dird Oct 19 '16 at 13:09
  • See http://stackoverflow.com/a/1348521/3832970 – Wiktor Stribiżew Oct 19 '16 at 13:23
  • Thanks. I needed to set the character set for some reason (although querying the database says UTF8, when php queries it it says latin1). Doesn't let me mark your comment as correct – Dird Oct 19 '16 at 16:29

1 Answers1

1

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

mysqli_set_charset($dbc, "utf8");
Dird
  • 39
  • 5