PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] How to give space in sentence in string with preg_replace?

 November 20, 2022     php, preg-replace, space     No comments   

Issue

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


Solution

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.



Answered By - Wiktor Stribiżew
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing