Take numbers together the letter with str_replace

Asked

Viewed 821 times

3

I am wanting to take a part of a string, more specifically numbers together with the letter, for example:

$string = "Parte da string - 60h"

Well, I use str_replace as follows:

$string = str_replace(' - ', '', $string);
$string = str_replace('[ˆ0-99]h', '', $string);

The problem is that I get the following string : Part of string60h. It seems to me that the second use of str_replace is not being made. Someone can help me?

1 answer

5


The str_replace does not accept regular expression, you can use the preg_replace ().

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.