PHP crawls the page and returns the regular truncation value, as long as the intermediate value is used

Source: Internet
Author: User
After the PHP captures the page, the regular truncation value is obtained as long as the intermediate value page gets the following value & nbsp; & lt; dt & gt; Shenzhen ABC Electronics Co., Ltd. & lt;/dt & gt; & nbsp; & lt; dd & gt; & lt; span & gt; Contact: & lt;/span & gt; Mr. Zhang & lt;/dd & gt; & lt; the regular truncation value after the page is captured by ddstyle PHP, as long as the value in the middle
Obtain the following values on the page:

Shenzhen ABC Electronics Co., Ltd.

Contact: Mr. Zhang

URL: Http: // www.ABCDE.com

Fax:

Phone: 0755-888888888

Email: sales@ABCDE.com

Address: 9D, R Block, ABCDE building, shangbu South Road, Futian District, Shenzhen


How can I obtain variable information such as the company name, contact person, fax, phone number, email address, and address with the simplest regular expression? Basically, they are extracted separately.
,
.

------ Solution --------------------
PHP code
$ Str = <
  
   
Shenzhen ABC Electronics Co., Ltd. 
   
  
Contact: Mr. Zhang
URL: Http: // www.ABCDE.com
Fax:
Phone: 0755-888888888
Email: sales@ABCDE.com
Address: 9D, R Block, ABCDE building, shangbu South Road, Futian District, Shenzhen
Html; preg_match_all ('/<\/span> (.*?) <\/Dd> |
(. *) <\/Dt>/M', $ str, $ arr); print_r ($ arr );
------ Solution --------------------
PHP code
      Shenzhen ABC Electronics Co., Ltd.
Contact: Mr. Zhang
URL: Http: // www.ABCDE.com
Fax:
Phone: 0755-888888888
Email: sales@ABCDE.com
Address: 9D, R Block, ABCDE building, shangbu South Road, Futian District, Shenzhen
STR; preg_match_all ('/ ] *> (? :(.*?) : <\/Span> )? (? :] *> )? (.*?) (? : <\/Span> )? <\/D [dt]>/M', $ str, $ matches); print_r ($ matches [1]); print_r ($ matches [2]); /* Array ([0] => [1] => contact [2] => website [3] => Fax [4] => Phone [5] => email [6] => address) array ([0] => Shenzhen ABC Electronics Co., Ltd. [1] => Mr. Zhang [2] => Http: // www.ABCDE.com [3] => [4] => 0755-888888888 [5] => sales@ABCDE.com [6] => 9D, R Block, ABCDE building, shangbu South Road, Futian District, Shenzhen )*/
------ Solution --------------------
Er...
If you want to improve the performance, follow the following steps to cut the string...

PHP code
$ Str = <
      
       
Shenzhen ABC Electronics Co., Ltd. 
       
    
Contact: Mr. Zhang
URL: Http: // www.ABCDE.com
Fax:
Phone: 0755-888888888
Email: sales@ABCDE.com
Address: 9D, R Block, ABCDE building, shangbu South Road, Futian District, Shenzhen
HTML; echo strip_tags ($ str );

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.