Need Help on RegEx and PHP

Discussion in 'PHP' started by Abhik, Sep 27, 2012.

  1. #1
    Hi,
    Need a little help on Regular Expression and PHP.

    Here is my situation:

    I need to find a two part string similar to this in a page:

    [abcdefghij klmnopqrst] < There is a space between the words to separate.

    Now I want to divide it two strings

    $att1 = abcdefghij
    $att2 = klmnopqrst
    PHP:
    Now execute a PHP code similar to this;
    if ($att1 == 'A certain Word') {
    
    - Codes Here -
    
    } elseif ($att1 == 'Another Certain Word') {
    
    - Codes Here -
    
    } else {
    
    -Codes Here -
    }
    PHP:
    How can I do that?
     
    Abhik, Sep 27, 2012 IP
  2. imocoder

    imocoder Member

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    To divide a string by space, you can use this code:

    
    $string = "abcdefghij klmnopqrst";
    $splitted = preg_split("/ /", $string);
    $att1 = $splitted[0];
    $att2 = $splitted[1];
    
    echo $att1.'<br />';
    echo $att2.'<br />';
    
    PHP:
     
    imocoder, Sep 29, 2012 IP