user930026
user930026

Reputation: 1657

preg match if found exclude that string php

I am stuck in a very simple PHP problem. I am having a string as $a = "123 text"; or it can also be $a="lorem ipsum 1234 dummy text";

I want that the output shall be $a="text"; or $a="lorem ipsum dummy text"; In short I want to exclude the number that can either be 123 or 12345 or anything else.

I have tried $except_txt = "text 123456 dummy"; $pattern = "/12/"; $replacement = ""; $path = preg_replace($pattern, $replacement, $except_txt);

but I get output as $except_txt = "text 3456 dummy";

Upvotes: 0

Views: 73

Answers (2)

This code snippet solves your problem:

$a = "lorem ipsum 1234 dummy text";
$a = preg_replace("/[\d]/", "", $a);
echo $a;

Upvotes: 2

Benten
Benten

Reputation: 1039

Try:

preg_replace("/(\d)+/", "", $except_txt);

Upvotes: 0

Related Questions