2

Here's i have an issue : sentence : "12223233 sekamar berempat"

$kamar = $_POST['kamarpilihan'];
 $kamarhuruf = preg_replace("/[^a-z]+""/", "", $kamar);

result: sekamarberempat

expectation: sekamar berempat

thank you

1
  • preg_replace("/[^a-z]+/", " ", $kamar)? trim(preg_replace("/[^a-z]+/", " ", $kamar))? Feb 10, 2021 at 9:09

1 Answer 1

0

You can replace all chars other than lowercase letters with a space and trim the string:

$kamar = "12223233 sekamar berempat";
echo trim(preg_replace("/[^a-z]+/", " ", $kamar));
// => sekamar berempat

See the PHP demo.

2
  • pardon me, but how do i change the first character to capital? like "sekamar" to "Sekamar"? Feb 10, 2021 at 9:49
  • @rayhanaulian Use ucfirst. Feb 10, 2021 at 9:51

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.