Page 1 of 1

Remove a section of a string before a period

Posted: Wed Jan 27, 2010 9:33 am
by dimxasnewfrozen
I'm not quite sure if this requires a str_replace() function or a regular expression.

I am querying a value that will always have a period in it. IE (test.test1)

I need to get the contents to the right of the period so in that case: test1 becomes the new string..

I looked at substr_replace which may do what I need to do but it uses an absolute value for the string characters/index which isn't ideal.

Re: Remove a section of a string before a period

Posted: Wed Jan 27, 2010 10:11 am
by AbraCadaver
Several ways to do it using the string functions to find the position of the period, but here's another:

Code: Select all

array_pop(explode('.', 'test.test1', 2));
A string function version:

Code: Select all

$test = 'test.test1';
 
substr($test, strpos($test, '.')+1);
//or
substr(strchr($test, '.'), 1);