maxudaskin Posted January 19, 2008 Share Posted January 19, 2008 How would I be able to remove the OOM from OOM0100 if $var1 = "OOM0100"; ? Quote Link to comment https://forums.phpfreaks.com/topic/86727-solved-remove-certain-text-from-variable/ Share on other sites More sharing options...
marcus Posted January 19, 2008 Share Posted January 19, 2008 <?php $string = "OOM0100"; if(preg_match("/OOM/is",$string)){ $string = preg_replace("/OOM/is","",$string); } echo $string; ?> 0100 Quote Link to comment https://forums.phpfreaks.com/topic/86727-solved-remove-certain-text-from-variable/#findComment-443212 Share on other sites More sharing options...
Ken2k7 Posted January 19, 2008 Share Posted January 19, 2008 Don't use preg_match. I learned that the hard way. You don't need RegExp to do this. str_replace("OOM","",$str); Quote Link to comment https://forums.phpfreaks.com/topic/86727-solved-remove-certain-text-from-variable/#findComment-443215 Share on other sites More sharing options...
marcus Posted January 19, 2008 Share Posted January 19, 2008 that will remove only OOM not oOm or Oom or ooM or OOm, etc... Quote Link to comment https://forums.phpfreaks.com/topic/86727-solved-remove-certain-text-from-variable/#findComment-443217 Share on other sites More sharing options...
Ken2k7 Posted January 19, 2008 Share Posted January 19, 2008 that will remove only OOM not oOm or Oom or ooM or OOm, etc... The OP didn't say he wanted to remove text like oOm, Oom, ooM or OOm. In codes, it would be very inconsistent to have letters like those and you have to use RegExp to match them. Quote Link to comment https://forums.phpfreaks.com/topic/86727-solved-remove-certain-text-from-variable/#findComment-443220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.