Codice PHP:
<?php
$con = mysql_connect("localhost","joomla","joomla");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("old", $con);
$result = mysql_query("SELECT * FROM jos_content");
$cont = 0;
while($row = mysql_fetch_array($result))
{
$cont++;
/* $metakey = $row['metakey'];
$metadesc = $row['metadesc'];
$metadata = $row['metadata'];
$introtext = $row['introtext'];*/
$title = $row['title'];
$alias = $row['alias'];
$title_alias = $row['title_alias'];
$introtext = $row['introtext'];
$fulltext = "fulltext";
$state = $row['state'];
$sectionid = $row['sectionid'];
$mask = $row['mask'];
$catid = $row['catid'];
$created = $row['created'];
$created_by = $row['created_by'];
$created_by_alias = $row['created_by_alias'];
$modified = $row['modified'];
$modified_by = $row['modified_by'];
$checked_out = $row['checked_out'];
$checked_out_time = $row['checked_out_time'];
$publish_up = $row['publish_up'];
$publish_down = $row['publish_down'];
$images = $row['images'];
$urls = $row['urls'];
$attribs = "show_title=
link_titles=
show_intro=
show_section=
link_section=
show_category=
link_category=
show_vote=
show_author=
show_create_date=
show_modify_date=
show_pdf_icon=
show_print_icon=
show_email_icon=
language=
keyref=
readmore=";
$version = $row['version'];
$parentid = $row['parentid'];
$ordering = $row['ordering'];
$metakey = $row['metakey'];
$metadesc = $row['metadesc'];
$access = $row['access'];
$hits = $row['hits'];
$metadata = $row['metadata'];
// extraction of metadesc and metakey from metadata field
$pattern_desc = '{tion=(.*?)meta_k}si';
$pattern_key = '{words=(.*?)robots=}si';
//$matchcount = preg_match_all($pattern_long, $data, $matches);
$matchcount_desc = preg_match_all($pattern_desc, $metadata, $matches_desc);
$matchcount_key = preg_match_all($pattern_key, $metadata, $matches_key);
echo("<pre>\n");
if ($matchcount_desc > 0 || $matchcount_key > 0) {
// print_r($matches);
for($i = 0; $i < $matchcount_desc || $i < $matchcount_key; $i++) {
echo("\nMatch #" . ($cont) . ":\n");
$metadesc_new = ($matches_desc[1][$i]); // print 1st capture group for match number i
$metakey_new = ($matches_key[1][$i]); // print 1st capture group for match number i
if($metadesc == '' || !$metadesc || $metakey == '' || !$metakey){
/* mysql_query ("INSERT INTO `jos_content` (metadesc,metakey,`introtext`) VALUES ('$metadesc_new','$metakey_new',`$introtext`);") or die(mysql_error()); */
mysql_query("insert into jos_content (
title,
alias,
title_alias,
`introtext`,
`fulltext`,
state,
sectionid,
mask,
catid,
created,
created_by,
created_by_alias,
modified,
modified_by,
checked_out,
checked_out_time,
publish_up,
publish_down,
images,
urls,
attribs,
version,
parentid,
ordering,
metakey,
metadesc,
access,
hits,
metadata
) VALUES ('$title','$alias','$title_alias','$introtext','$fulltext','$state','$sectionid','$mask','$catid','$created','$created_by','$created_by_alias','$modified','$modified_by','$checked_out','$checked_out_time','$publish_up','$publish_down','$images','$urls','$attribs','$version','$parentid','$ordering','$metakey_new','$metadesc_new','$access','$hits','$metadata')") or die(mysql_error());
}
}
} else {
echo('No matches');
}
echo("\n</pre>");
}
mysql_close($con);
?>