In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to convert table content in php into an array", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to convert table content in php into an array.
Php table content to array methods: 1, to create a PHP sample file; 2, through the "function tdToArray ($table) {.}" method to convert each row and column of the HTML table into an array.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
Php regular matches the table in the web page html to convert the content into an array
When docking with JD.com vop, when JD.com returns the specification attribute, he returns the style in html format, for example
$date=' main brand good boy main material PP gauge Lattice 800mm*445mm*225'
As for the table above, the preview is
The next step is to extract, and the idea of extraction is to delete the tags such as regular tags first.
Paste the code first
/ / php collects table table data (converts each row of the HTML table to an array) function tdToArray ($table) {$table = preg_replace ("'] *? >'si", ", $table); $table = preg_replace ("'] *? >'si ",", $table); $table = preg_replace ("'] *? >'si", ", $table); $table = str_replace ("," {tr} ", $table) $table = str_replace ("", "{td}", $table); / remove the HTML tag $table = preg_replace ("''si", "", $table); / / remove the white space character $table = preg_replace ("'([rn]) [s] +", ", $table); $table = str_replace (", ", $table); $table = str_replace (",", $table) $table = explode ('{tr}', $table); array_pop ($table); foreach ($table as $key= > $tr) {/ / you can add the corresponding replacement $td = explode ('{td}', $tr); array_pop ($td); $td_array [] = $td;} return $td_array;}
Follow the process with debug, observe each step, without going into details, put a variable of the last $table
Variables after array_pop
It is as follows
The above\ r\ nis to distinguish between line breaks, which can be replaced with str_replace, and the title can also be replaced, as follows
Final effect
The above is all the content of the article "how to convert table content in php into an array". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.