Easy preg_replace help?

Hi guys, l have a few strings for example:


What l’d like to do is strip off the + signs and anything after them,
So in this example both strings would become ‘testing’

Can anyone help me with a preg_replace that would solve this problem for me?


is your pattern.

Thanks for your help, l’m still doing something wrong, so here’s what l’m running:

$string = 'test+123';
$string= preg_replace('~+.*$~', '', $string);

But it’s not doing anything. I would it expect it to return ‘test’


You forgot the \ in front of the +

$string = 'test+123'; 
$string= preg_replace('~\\+.*$~', '', $string); //need to escape the +  

Awesome, thanks again!