Reputation: 1583
I have database and in one column and someone had a code like this. This is just one entry of column
<span style="vertical-align: middle; font-size: 40px; line-height: 2px;">“</span> Some text<span style="vertical-align: middle; font-size: 40px;line-height:30px">”</span><br/>
<strong>Name, </strong><br/><br/> <strong style="font-style: italic;"> Location</strong><br/><br/><br/>
<span style="vertical-align: middle; font-size: 40px; line-height: 2px;">“</span> Sometext<span style="vertical-align: middle; font-size: 40px;line-height:30px">”</span><br/>
<strong>Name, </strong><br/><br/> <strong style="font-style: italic;"> Sydney</strong><br/><br/><br/>
In php all he is doing is
echo $row['table_name'];
Now I have created a separate table for this with fields
id, tName, tLocation, Text
I want to enter all the data in the above column to this table but as the data is too much so I cant do data entry
e.g the entry of above code will go like
tName = Name
tLocation = Sydney
Text = Some text
Can we archive this through some query or even PHP code? If yes then how
Thanks
Upvotes: 1
Views: 53
Reputation: 879
This can't be done easily with SQL, however you can make a script and match the content using regex.
$data = <<<EOD
<span style="vertical-align: middle; font-size: 40px; line-height: 2px;">“</span> Some text<span style="vertical-align: middle; font-size: 40px;line-height:30px">”</span><br/>
<strong>Name, </strong><br/><br/> <strong style="font-style: italic;"> Location</strong><br/><br/><br/>
<span style="vertical-align: middle; font-size: 40px; line-height: 2px;">“</span> Sometext<span style="vertical-align: middle; font-size: 40px;line-height:30px">”</span><br/>
<strong>Name, </strong><br/><br/> <strong style="font-style: italic;"> Sydney</strong><br/><br/><br/>
EOD;
echo $data;
echo "<pre>";
//Name part
preg_match_all('@<strong>(.+), </strong><br/><br/> <strong style="font-style: italic;">@', $data, $matches);
var_dump($matches[1]);
//sometext part
preg_match_all('@<span style="vertical-align: middle; font-size: 40px; line-height: 2px;">“</span>(.+)<span style="vertical-align: middle; font-size: 40px;line-height:30px">”</span><br/>@', $data,$matches);
var_dump($matches[1]);
//Location part
preg_match_all('@<strong style="font-style: italic;">(.+)</strong>@', $data,$matches);
var_dump($matches[1]);
Upvotes: 2