Remove String Part with PHP

1

I have the following String.

name-any-ID 12

I want a PHP expression that removes the -ID 12 string.

NOTE: The value can change as for example -ID 23.

    
asked by anonymous 02.07.2018 / 19:08

1 answer

3

You can use the strstr() function to break and get the left part of the string, an important detail is to enter the third argument that returns the left part, by default it returns the right.

$str = 'nomequalquer-ID 12';
$novo = strstr($str, '-ID', true);

echo "<pre>";
print_r($novo);
    
02.07.2018 / 19:23