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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    extract specific words out of a string

    Hi;

    How could i extract specific words out of a string and put into an array, please.

    Eg;
    $string="talking animails and get rid off talking about this facebook";
    $term="talking a";

    The final result will be:

    $final[]="talking animails, talking about ",

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    <?php
    
    $string = 'talking animails and get rid off talking about this facebook';
    $regex = '~talking a[\w]+~im';
    
    preg_match_all($regex, $string, $matches);
    
    print_r($matches[0]);
    
    ?>


  •  

    Posting Permissions

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