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 );