www.webdeveloper.com
Results 1 to 7 of 7

Thread: How to Hide Part of String?

  1. #1
    Join Date
    Jan 2003
    Posts
    218

    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
    Join Date
    Mar 2011
    Posts
    1,137
    You're not "hiding" anything. You're extracting a substring. Start with http://www.php.net/manual/en/function.substr.php
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jan 2003
    Posts
    218
    Yes. That's correct. But the string length/content is going to vary. Not sure substr() would handle that. Thoughts?

  4. #4
    Join Date
    Mar 2011
    Posts
    1,137
    If you have a specific marker of some kind, you can use strpos() to locate it in the original string and then use the result in substr(). See http://www.php.net/manual/en/function.strpos.php
    Rick Trethewey
    Rainbo Design

  5. #5
    Join Date
    Jan 2003
    Posts
    218
    I stil don't know how this would look with strpos(). Can you offer an example?

  6. #6
    Join Date
    Mar 2011
    Posts
    1,137
    Extracting substrings is a common task, and like many programming issues, there are several different ways of doing it. The best choice depends on exactly what you're trying to do. It would also be helpful to have an idea of your programming skills so that I'm not just spoon-feeding you code that might solve your example problem, but would be of little use in solving your actual problem. Could you post some of your existing code so I can get an idea of what you're trying to do and where you are at the moment.
    Rick Trethewey
    Rainbo Design

  7. #7
    Join Date
    Jan 2003
    Posts
    218
    Thank you for the explanation. I've got it worked out. Ended up using strtok().

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles