Regular expression-php extracts text and href of a tag under the specified div in html

Source: Internet
Author: User
Solved, a little messy, just speed. {Code...} URL: www.hkxy.edu.cn: how can I extract text and href of element a under. offer_box_wide1? Tutorial

Solved, a little messy, just speed.


  (.*?)

% Sim '; preg_match_all ($ pa, $ response, $ arr); $ pa =' % (.*?) % Sim '; preg_match_all ($ pa, $ response, $ arr); $ result = array (); $ number = count ($ arr [1]); for ($ I = 0; $ I <$ number; $ I ++) {$ temp = explode ('/', $ arr [1] [$ I]); // print_r ($ temp); exit (); $ result [$ temp [2] [$ I] ['src'] =' http://www.hkxy.edu.cn '. $ Arr [1] [$ I]; $ result [$ temp [2] [$ I] ['title'] = $ arr [2] [$ I];} echo JSON ($ result); function arrayRecursive (& $ array, $ function, $ apply_to_keys_also = false) {static $ recursive_counter = 0; if (++ $ recursive_counter> 1000) {die ('possible deep recursion attack');} foreach ($ array as $ key => $ value) {if (is_array ($ value )) {arrayRecursive ($ array [$ key], $ function, $ apply_to_keys_also);} else {$ array [$ ke Y] = $ function ($ value);} if ($ apply_to_keys_also & is_string ($ key) {$ new_key = $ function ($ key); if ($ new_key! = $ Key) {$ array [$ new_key] = $ array [$ key]; unset ($ array [$ key]) ;}}$ recursive_counter --;} /*************************************** * ************************ convert an array to a JSON string (compatible with Chinese characters) * @ param array $ array the array to be converted * @ return string the converted json string * @ access public ***************** **************************************** * ***/function JSON ($ array) {arrayRecursive ($ array, 'urlencode', true); $ json = json_encode ($ array); return urldecode ($ json );}

URL: http://www.hkxy.edu.cn/

:
How can I extract text and href of element a under. offer_box_wide1? Tutorial

Reply content:

Solved, a little messy, just speed.


  (.*?)

% Sim '; preg_match_all ($ pa, $ response, $ arr); $ pa =' % (.*?) % Sim '; preg_match_all ($ pa, $ response, $ arr); $ result = array (); $ number = count ($ arr [1]); for ($ I = 0; $ I <$ number; $ I ++) {$ temp = explode ('/', $ arr [1] [$ I]); // print_r ($ temp); exit (); $ result [$ temp [2] [$ I] ['src'] =' http://www.hkxy.edu.cn '. $ Arr [1] [$ I]; $ result [$ temp [2] [$ I] ['title'] = $ arr [2] [$ I];} echo JSON ($ result); function arrayRecursive (& $ array, $ function, $ apply_to_keys_also = false) {static $ recursive_counter = 0; if (++ $ recursive_counter> 1000) {die ('possible deep recursion attack');} foreach ($ array as $ key => $ value) {if (is_array ($ value )) {arrayRecursive ($ array [$ key], $ function, $ apply_to_keys_also);} else {$ array [$ ke Y] = $ function ($ value);} if ($ apply_to_keys_also & is_string ($ key) {$ new_key = $ function ($ key); if ($ new_key! = $ Key) {$ array [$ new_key] = $ array [$ key]; unset ($ array [$ key]) ;}}$ recursive_counter --;} /*************************************** * ************************ convert an array to a JSON string (compatible with Chinese characters) * @ param array $ array the array to be converted * @ return string the converted json string * @ access public ***************** **************************************** * ***/function JSON ($ array) {arrayRecursive ($ array, 'urlencode', true); $ json = json_encode ($ array); return urldecode ($ json );}

URL: http://www.hkxy.edu.cn/

:
How can I extract text and href of element a under. offer_box_wide1? Tutorial

The simplest method is phpQuery.

See PHP Simple html dom Parser
Http://simplehtmldom.sourceforge.net/
You can flexibly operate html like the jquery selector.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.