Remove Part of String with PHP

Asked

Viewed 327 times

1

I got the following String.

nameID 12

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

OBS.:The value can be changed as for example -ID 23.

1 answer

3


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

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

echo "<pre>";
print_r($novo);

Browser other questions tagged

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