Reputation: 7
I want something like this:
$name = str_replace(".", " ", $name);
but if I have this name:
Text.Text.text.text.Text.5.0.1
I want to remove the dots only from letters and from "t.5". Text must result:
Text Text text text Text 5.0.1
Upvotes: 1
Views: 64
Reputation: 3300
Try preg_replace('/([^\d])\./', '$1 ', $name)
/([^\d])\./
matches a non-digit followed by a .
. Replaces it with $1
, the non-digit you found, followed by a space.
Edit: given refined requirement from comment below, that "." are removed only if there's a non-digit before OR after, answer is (requires 2 statements):
$name = preg_replace('/([^\d])\./', '$1 ', $name);
$name = preg_replace('/\.([^\d])/', ' $1', $name);
Upvotes: 1