I am trying to get the first 10 characters of a string and want to replace space with '_'
.
I have
$text = substr($text, 0, 10);
$text = strtolower($text);
But I am not sure what to do next.
I want the string
this is the test for string.
become
this_is_th
Simply use str_replace:
You would do this after your previous
substr
andstrtolower
calls, like so:If you want to get fancy, though, you can do it in one line: