how to insert array generated by Preg_match_all in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhishek1234321
    New Member
    • Jul 2010
    • 18

    how to insert array generated by Preg_match_all in database

    Code:
    mysql_query("CREATE TABLE $value (Subject VARCHAR(200), External int(3))");
    		preg_match_all('/<i>(.*?)<\/i>/si', $matches[0], $submatch, PREG_SET_ORDER);
    		mysql_query("INSERT INTO $value (Subject) VALUES ('$submatch[2][1]')");
    its only a part of the code
    $matches[0] contains html data with tags
    i'm matching the data between the <i> and </i> tags
    and i guess its been stored in $submatch array

    now i want to knw a way through which i can insert each match into a different row using mysql query

    i tried running two foreach loops and tried inserting like this
    Code:
    foreach ($submatch as $tempone) {
    
                    foreach ($tempone as $key=>$temptwo) 
                {
                    mysql_query("INSERT INTO $value (Subject) VALUES ('$temptwo')");    
            }
         }
    but whats happening is the array $submatch contains the pattern with the tags and also without tags
    that is for each match there are two array positions like
    $submatch[0][0] contains <i>xysdbhdg</i> and
    $submatch[0][1] contains xysdbhdg


    and both are getting inserted... i wanna insert oly ones which are like $submatch[0][1] contains xysdbhdg i mean ones without the tags :)
  • abhishek1234321
    New Member
    • Jul 2010
    • 18

    #2
    no one knwos the solution??

    Comment

    Working...