...

View Full Version : regex split string, remove prefix



gorilla1
12-13-2010, 06:59 PM
I would like to remove from the beginning of a string everything up to and including the character '|' . I think I need to use regex to do this, but am not sure what the regular expression needs to be.

G

bazz
12-13-2010, 07:24 PM
show us the actual string please.

gorilla1
12-13-2010, 07:31 PM
Thanks for the reply, Bazz. The string is variable. It would have the form '[any charachter string]|[any character string]'.

I think this would be one way to do it:
$splarr = preg_split("/[\|]+/", $lineout);
echo "$splarr[1]";

G

kbluhm
12-13-2010, 10:37 PM
No regex necessary:


$string = 'this is text|this is more text|this is even more text';

$string = explode( '|', $string, 2 );
$string = end( $string );

echo $string; // this is more text|this is even more text

...or:


$string = 'this is text|this is more text|this is even more text';

$string = strstr( $string, '|' );
$string = ltrim( $string, '|' );

echo $string; // this is more text|this is even more text

...or:


$string = 'this is text|this is more text|this is even more text';

if ( FALSE !== ( $pos = strpos( $string, '|' ) ) )
{
$string = substr( $string, $pos );
}

echo $string; // this is more text|this is even more text



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum