// loop through array foreach($results as $key => $value) { // remove the markup so we're just left with the name $sp = strpos($value, $starttag, 0) + strlen($starttag); $ep = strrpos($value, $endtag); $name = substr($value, $sp, $ep-$sp); // set query $query = "INSERT INTO people SET people_name = '$name', post_id = '$post_id'"; // run query $result = mysql_query($query); }