#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    219
    Rep Power
    11

    Question How to Hide Part of String?


    How would I hide part of a string (up to and including a slash)? So if my string is "firstpart/secondpart" -- I need it to only output "secondpart".

    Thank you for your help.
  2. #2
  3. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by msmith29063
    How would I hide part of a string (up to and including a slash)? So if my string is "firstpart/secondpart" -- I need it to only output "secondpart".

    Thank you for your help.
    The method used would depend on the possible strings you're talking about. We'd have to see a series of possible formats to provide the most succinct solution.

    If it's always going to be of the format stated above:
    PHP Code:
    print explode("/",$string)[1]; 
    The function()[1] thing I think was just added in a recent PHP version, but I can't find which...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    219
    Rep Power
    11
    I tried using:

    print explode("/",$string)[1];

    But returned an error. It's probably not supported in the PHP version on the server. Any other options?

    Thank you.
  8. #5
  9. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    PHP 5.5. For now you should just go with a temporary variable.
    PHP Code:
    list(, $second) = explode("/"$string);
    print 
    $second
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    219
    Rep Power
    11
    Crap. I just realized I have this backward. Sorry. I need to display only the FIRST part of the string up to the slash:

    firstpart/secondpart

    Would output:

    firstpart

    Do I use the same method?

    Sorry about that. Thank you for your help.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    PHP Code:
    print strtok('foo/bar''/'); 

    Comments on this post

    • requinix agrees : an under-appreciated function
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    219
    Rep Power
    11
    That did it. Makes sense. Thanks for hanging in there with me.

IMN logo majestic logo threadwatch logo seochat tools logo