Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to strip a sentence just keep letters, numbers, spaces

Tags:

regex

I have a lot of sentences that need to be cleaned up from all the special characters and punctuations (I want to keep just the letters and numbers and spaces), for example:

$string = "TB Avrupa ve Türkiye'nin en iyi oranlari ile Lider Bahis Sitesi!!";
$final_title = preg_replace('/[^a-z]+/i', '', $string); 

This remove everything (with spaces) I need to keep spaces can i add anything to the previous line to achieve this ??

Expected output :

TB Avrupa ve Türkiyenin en iyi oranlari ile Lider Bahis Sitesi
like image 902
Basel Avatar asked Oct 21 '25 15:10

Basel


1 Answers

I want to keep just the letters and numbers and spaces

You can use this regex to remove everything other than english letters, digits and spaces:

preg_replace('/[^a-z\d ]+/i', '', $string); 
like image 131
anubhava Avatar answered Oct 23 '25 07:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!