I have a problem with explode() function. I use the function to explode strings like "Name: Replica" but sometimes in the string has 2 or more colons ( ":" ) and there is the problem because my script is: Example: "Name: replica:replica2:replica3"
$explode = explode(":", $string);
$query = "INSERT INTO `table` (`field_1`, `field_2`) VALUES ('".$explode[0]."', '".$explode[1]."')";
And I need any solution for this problem. Because when I split the string after first colon ( ":" ) the second part must be the last part.
I think you want to use the 'limit' (third) argument to explode()
:
list($attribute, $value) = explode(":", $string, 2);
That will make sure you only get two results.