Hamza
Hamza

Reputation: 1583

Move data from one column to a table

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;">&#8220;</span> Some text<span style="vertical-align: middle; font-size: 40px;line-height:30px">&#8221;</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;">&#8220;</span> Sometext<span style="vertical-align: middle; font-size: 40px;line-height:30px">&#8221;</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

Answers (1)

enterx
enterx

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;">&#8220;</span> Some text<span style="vertical-align: middle; font-size: 40px;line-height:30px">&#8221;</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;">&#8220;</span> Sometext<span style="vertical-align: middle; font-size: 40px;line-height:30px">&#8221;</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;">&#8220;</span>(.+)<span style="vertical-align: middle; font-size: 40px;line-height:30px">&#8221;</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

Related Questions