The following code will be displayed below
('nice apple'),(' nice yellow banana'),(' good berry ')
what i need to do is what i need them to be
('nice-apple'),(' nice-yellow-banana'),(' good-berry ')
The problem is that I could not touch $ str, and then I need to use a “-” to connect the words if there is space between them. If you use the str_replace space, it will be something like ---- nice-apple -. how can I achieve something like this ("nice-apple"), appreciate it.
<?php
$str="nice apple,
nice yellow banana,
good berry
";
echo $str = "('" . implode("'),('", explode(',', $str)) . "')";
?>
source
share