我用你的方法出来的结果还是不对。。不过还是谢谢你。。不然我也不知道怎样做
下面是我的写法
function get_between($input, $start, $end)
{
$substr = substr($input, strlen($start)+strpos($input, $start), (strlen($input) - strpos($input, $end))*(-1));
return $substr;
}
// Connects to your Database
$conn = mysql_connect("[datahost]", "[username]", "[password]");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("[mydatabase]")) {
echo "Unable to select [mydatabase]: " . mysql_error();
exit;
}
$sql = "SELECT * FROM [table1]";
$res = mysql_query($sql);
if (!$res) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($res) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while($row = mysql_fetch_assoc($res))
{
$info = $row['info'];
$name = $row['name'];
$time = $row['time'];
$info = str_replace("X-LIC-LOCATION", "X", $info);
$summary = get_between($info, "SUMMARY:", "DATESTART:");
$location = get_between($info, "LOCATION:", "TIMEZONE:");
$description = get_between($info, "DESCRIPTION:", "END");
$sql = "INSERT INTO [table2] (subject, location, description, name, time) VALUES ('$summary', '$location', '$description', '$name', '$time')";
$res_insert = mysql_query($sql);
echo $description;
echo $location;
echo $summary;
} |