preg_split help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: preg_split help

  1. #1
    Join Date
    Dec 2007
    Posts
    41

    Resolved [Solved] preg_split help

    Hello, I've read a couple tutorials on regular expressions but I just can't wrap my head around them. I am trying to split a string into an array using preg_split but so far I can't create a expression that will work.

    The type of data I would be working is like:
    Code:
    [Something][123456789][Hello]
    and I would like to split that into three separate places on an array like:
    Code:
    0 => Something
    1 => 123456789
    2 => Hello
    Anyone know how to do this?
    Last edited by Hellboyz; August 29th, 2010 at 12:19 AM.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,881

    Re: preg_split help

    Instead, why don't you use preg_match_all()?

    PHP Code:
    <?php
    $str 
    '[Something][123456789][Hello]';
    $pattern '/\[(.*?)\]/';
    preg_match_all($pattern$str$matches);
    print_r($matches[1]);
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Dec 2007
    Posts
    41

    Re: preg_split help

    Thank you PeejAvery, your code worked perfectly and thanks for the suggestion.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center