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 2I 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.
-
Surface object
The core concept in the face object is interface. through reasonable abstraction, if can be reduced.
-
Pattern matching
You can also use pattern matching. switch case itself is a pattern matching.
Phpquery is good. why not?