I would like to turn a variable like this. $var = "sample1"; Into this. $var = "sample"; As far as I know str_replace wont work because the final character and the preceding characters will constantly vary.