Take numbers together with str_replace

2

I want to take a part of a string, specifically numbers next to the letter, such as:

$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 done. Can someone help me?

    
asked by anonymous 13.04.2018 / 20:50

1 answer

4

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

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