Questions about PHP Regular matching to take out data

Source: Internet
Author: User
Questions about PHP Regular matching to take out data
The following is a partial processing of source code
 $exam = Curl_init ("http://exam.hhit.edu.cn/fgquery.do?status=lowquery&tsid=2012120348");
curl_setopt ($exam, Curlopt_returntransfer, true); Get Data back
curl_setopt ($exam, Curlopt_binarytransfer, true); Gets the data back when Curlopt_returntransfer is enabled
$exam =curl_exec ($exam);
$exam = Preg_replace ("' ]*?> ' si ', ' ", $exam);
$exam = Preg_replace ("' ]*?> ' si", "", $exam);
$exam = Preg_replace ("' ]*?> ' si", "", $exam);
$exam = Str_replace ("", "{tr}", $exam);
$exam = Str_replace ("", "{td}", $exam);
Remove HTML Tags
$exam = Preg_replace ("' <[/!") *? [^<>]*?> ' si ', ' ", $exam);
Remove whitespace characters
$exam = Preg_replace ("' ([RN]) [s]+ '", "", $exam);
$exam = Preg_replace ('//', "", $exam);
$exam = Str_replace ("", "" ", $exam);
$exam = Str_replace ("", "" ", $exam);
$exam = Explode (' {tr} ', $exam);
Array_pop ($exam);
Print_r ($exam);
?>

What I want is to take out the following piece of data into the array, do not know how to write, the first contact with the regular feel do not understand, thank you to the great gods!

Number {TD}
Course {TD}
Date {TD}
Time {TD}
class {TD}
Examination Room {TD}
Classroom Teacher {TD}


1{TD}
Fluid Dynamics {TD}
2014-11-0600:00:00.0
{TD}
14:00-16:00{TD}
Civil 122{TD}
Ⅲ-209{TD}
Sinina {TD}

------to solve the idea----------------------
That's what you're going to do.
Print_r (Array_map (NULL, explode (' {TD} ', $exam []), explode (' {TD} ', $exam [20]));
Array
(
[0] = = Array
(
[0] = = number
[1] = 1
)

[1] = = Array
(
[0] = Course
[1] = Fluid mechanics
)

[2] = = Array
(
[0] = Date
[1] = 2014-11-0600:00:00.0
)

[3] = = Array
(
[0] = time
[1] =
)

[4] = = Array
(
[0] = Class
[1] = Civil Engineering 122
)

[5] = = Array
(
[0] = = Examination Room
[1] =>ⅲ-209
)

[6] = = Array
(
[0] = = Instructor
[1] = Sinina
)

[7] = = Array
(


)

)

It's still like that.
Print_r (Array_combine (Explode (' {TD} ', $exam []), explode (' {TD} ', $exam [20]));
Array
(
[No.] = 1
  • 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.