I want to remove everything except Alphabets and spaces in php string.
$status = "1 (Delivered to customer)";
$status = preg_replace('/\PL/u', '', $status);
//output
echo $status;
The output is: Deliveredtocustomer
I want output: Delivered to customer
How to fix this?
Regards
CodePudding user response:
I use this and it worked.
$status = preg_replace("/[^ \w] /", "", $status);
$status = preg_replace('/[0-9] /', '', $status);
$status = trim($status);
Output = Delivered to customer
CodePudding user response:
You can do it in just one go. Anything that is not an alphabet or space(performing a case insensitive search), just replace them with an empty string.
<?php
$status = "1 (Delivered to customer)";
echo preg_replace("/[^a-z\s] /i","",$status);