Horje
How to remove all number from a string php

For Western Arabic numbers (0-9):

$words = preg_replace('/[0-9]+/', '', $words);

For all numerals including Western Arabic (e.g. Indian):

$words = '१३३७';
$words = preg_replace('/\d+/u', '', $words);
var_dump($words); // string(0) ""
  • \d+ matches multiple numerals.
  • The modifier /u enables unicode string treatment. This modifier is important, otherwise the numerals would not match.

How to remove all numbers from string? PHP

I'd like to remove all numbers from a string [0-9]. I wrote this code that is working.
index.php
Example: PHP
<?php
$words = '१३३७ 11544 I love';
$words = preg_replace('/\d+/u', '', $words);
var_dump($words);
?>

Output should be:

How to remove all numbers from string? PHP




php remove number from line

Type:
Develop
Category:
Web Tutorial
Sub Category:
PHP String Tutorial
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference