If-php parses html, there may be many situations, except for constantly writing if... is there a better way to handle it?

Source: Internet
Author: User
Php parses html, which may occur in many cases. Is there a better way to handle it except for constantly writing if? Php parses html, which may occur in many cases. Is there a better way to handle it except for constantly writing if?

Reply content:

Php parses html, which may occur in many cases. Is there a better way to handle it except for constantly writing if?

Use PHP ready-made html dom library, such as Simple-HTML-DOM
Http://simplehtmldom.sourceforge.net/manual.htm

Amount... The switch statement is also acceptable ..

switch
Http://www.w3school.com.cn/php/php_switch.asp

Maybe you can find the logical relationship that does not require if. Or the data is often processed in a certain way.

For example, you can click the button to remove an element.


  Remove 1Remove 2

I am 1

I am 2

/* Js * // jQuery (". btn "). click (function () {if (jQuery (this ). attr ("id") = "btn") {jQuery ("# btn1 "). remove ();} if (jQuery (this ). attr ("id") = "btnbtn") {jQuery ("# btn2 "). remove () ;}}) // maybe we can find a link like this? JQuery (". btn"). click (function () {jQuery ("#" + jQuery (this). attr ("flag"). remove ();})

Switch case Statement

Change the following answer.

  1. Surface object
    The core concept in the face object is interface. through reasonable abstraction, if can be reduced.

  2. Pattern matching
    You can also use pattern matching. switch case itself is a pattern matching.

Phpquery is good. why not?

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.