Forum Moderators: coopster
I've got a self-coded cms that I use on my website.
I have a field in one of my databases that reads a name and a number - it is always in the format name_number, so e.g. andy_2 cheryl_14 peter_16 and so on.
What I want to do though is strip the _number part of it, so if I pass andy_2 to the function, the result would be just andy and so on.
Is doing a str_replace the best way to do this? If so, can anyone help with the Regex for this, as I'm having trouble working it out (I've only just dipped my toes in the water of doing str_replaces).
I had thought something like:-
$str = preg_replace ('/(.*?)\_(.*?)/is', '$1' , $str);
might have done it, but it doesn't - it just removes the underscore.
Thanks if anyone can help! :)
Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.
No more digging! ;)