www.webdeveloper.com
Results 1 to 4 of 4

Thread: Parsing a String - I need the last few characters only. How?

  1. #1
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364

    Parsing a String - I need the last few characters only. How?

    I have a string, let's say:

    This is string #4455
    I want to take this string and only show the "4455" at the end. Is there any way I can cut this string from the end until it touches the # sign? I suppose you can say I'm using the octothorpe as my delimiter. How would I do this?

    Thanks.

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    There are multiple ways you can approach this:

    PHP Code:
    $string 'This is string #4455';
    echo 
    $string '<br />';

    //REGULAR EXPRESSION
    if (preg_match('/(\d+)$/'$string$matches)) {
        echo 
    $matches[1] . '<br />';
    }

    //SPLITTING
    $parts explode('#'$string);
    echo 
    array_pop($parts); 

  3. #3
    Join Date
    Aug 2009
    Posts
    84
    hi, you can do it this way:

    PHP Code:
    $str "This is string #4455";

    $digits substr($str,strpos($str,'#')); 

    Support Chat software for your website

  4. #4
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364
    Thanks!! Got it!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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