$value) { $value = mysqli_escape_string($conn, $value); $value = str_replace("\n", "\\n", $value); $value = str_replace("\r", "\\r", $value); $fields[] = '`' . $field . '`'; $values[] = '\\\'' . $value . '\\\''; } printf('$exampleData[] = \'INSERT INTO %s(%s) VALUES(%s)\';' . "\n", $table, implode(',', $fields), implode(',', $values)); } mysqli_free_result($result); } // clean up mysqli_close($conn);