简体   繁体   English

将数据从一列移动到表

[英]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 在PHP中,他正在做的是

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 我想将上一列中的所有数据输入到该表中,但是由于数据过多,因此我无法进行数据输入

eg 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? 我们可以通过一些查询甚至PHP代码将其归档吗? If yes then how 如果是的话如何

Thanks 谢谢

This can't be done easily with SQL, however you can make a script and match the content using regex. 使用SQL很难做到这一点,但是您可以使用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]); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM