Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regex split string, remove prefix

    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

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    show us the actual string please.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    No regex necessary:
    PHP Code:
    $string 'this is text|this is more text|this is even more text';

    $string explode'|'$string);
    $string end$string );

    echo 
    $string// this is more text|this is even more text 
    ...or:
    PHP Code:
    $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:
    PHP Code:
    $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 
    Last edited by kbluhm; 12-14-2010 at 01:52 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •