Okay I'm using strip_tags
to get rid of html from when a user tags a post but when a user enters something like in the upcoming example.
I get five empty values entered into the database, which I don't want everything else is fine. How can i stop this?
,,,,,,,, ,, ,,,,a,d, <html> , ruby-on-rails , ad, <html>
I get the following entered into the database NOTE the commas are not entered into the database.
, , , a, d, , ruby-on-rails, ad,
Here is my code.
$tags = preg_split('/,/', strip_tags($_POST['tag']), -1, PREG_SPLIT_NO_EMPTY);
$tags = array_map('trim', $tags);
$tags = str_replace(' ', '-', $tags);
ONLY the following should be entered into the database.
a,d,ruby-on-rails,ad
Here is a quick example of my insert.
for ($x = 0; $x < count($tags); $x++){
$query1 = "INSERT INTO tags (tag) VALUES ('" . mysqli_real_escape_string($mysqli, strtolower($tags[$x])) . "')";
}