I am trying to use explode on the product name saved in my database. I have a product called: A4Tech KR-83FN Multimedia Bangla USB Black Comfort Round Edged Keycaps Normal Keyboard in the database. when I fetch the entry using select query and use explode on it, it's not working properly, and getting the following array:
array (size=4)
0 => string 'A4Tech' (length=6)
1 => string 'KR-83FN' (length=7)
2 => string 'Multimedia' (length=10)
3 => string 'Bangla USB Black Comfort Round Edged Keycaps Normal Keyboard' (length=68)
But, when I am copying the text and using explode() on it, it's working properly.
array (size=12)
0 => string 'A4Tech' (length=6)
1 => string 'KR-83FN' (length=7)
2 => string 'Multimedia' (length=10)
3 => string 'Bangla' (length=6)
4 => string 'USB' (length=3)
5 => string 'Black' (length=5)
6 => string 'Comfort' (length=7)
7 => string 'Round' (length=5)
8 => string 'Edged' (length=5)
9 => string 'Keycaps' (length=7)
10 => string 'Normal' (length=6)
11 => string 'Keyboard' (length=8)
The code is mentioned below:
<?php
$conn = new mysqli("localhost", "root", "", "dbname");;
$sql = "select * from products where name like '%A4Tech KR-83FN Multimedia%'";
$result = $conn->query($sql);
$row = $result->fetch_row();
$ss = $row[5];
//$ss = "A4Tech KR-83FN Multimedia Bangla USB Black Comfort Round Edged Keycaps Normal Keyboard";
$exploded = explode(" ",$ss);
var_dump($exploded);
I think I am missing something simple and it's the only product name that's having this issue.
I have another part of code after it, which replaces everything but a-zA-Z0-9 and space with "", it shouldn't replace the space but that part actually removes every bit of space from the fourth element of the following array. So, space is not getting considered as space.
array (size=4)
0 => string 'A4Tech' (length=6)
1 => string 'KR-83FN' (length=7)
2 => string 'Multimedia' (length=10)
3 => string 'Bangla USB Black Comfort Round Edged Keycaps Normal Keyboard' (length=68)
$cleaned = preg_replace("([^a-zA-Z0-9])","",$str);