When learning PHP, you may encounter the problem of judging PHP regular expressions. Here we will introduce the solutions to PHP regular expression problems and share them with you here. In some query websites and search engines, it is often used to determine whether a certain string is a standard IP address.
<ol class="dp-xml"> <li class="alt"><span><span>functionis_ip($gonten){ </span></span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">ip</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">explode</font></span><span>(”.”,$gonten); </span> </li> <li class="alt"> <span>for($</span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>;$i</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>count</SPAN></FONT></STRONG><SPAN>($ip);$i++) </SPAN></SPAN><LI class=""><SPAN>{ </SPAN><LI class=alt><SPAN>if($ip[$i]</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>255){ </span> </li> <li class=""><span>return(0); </span></li> <li class="alt"><span>} </span></li> <li class=""><span>} </span></li> <li class="alt"><span>returnereg(”^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$”,$gonten); </span></li> <li class=""><span>} </span></li> </ol>
$gonten is the string to be queried. You can use is_ip($gonten) to judge it and return FALSE and TRUE.
1. The eregi statement is case-insensitive
<ol class="dp-xml"><li class="alt"><span><span>if(eregi("^[a-zA-Z0-9]{8,10}$","999999999"))echo"是八到十位的数字与字母"; </span></span></li></ol>
2. ereg_replace to replace text in a case-sensitive manner
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"Thisisatest"</font></span><span>; </span></span></li> <li class=""><span>//替换is为was </span></li> <li class="alt"><span>echoereg_replace("is","was",$string); </span></li> </ol>
can also be used to backquote the characters in parentheses. 0 means all 1 means the first matching string, and so on up to 9! The usage of eregi_replace in the specific manual is case-insensitive and the replacement text is the same as above
3. Divide the string into different elements in a case-sensitive way. The split statement
<ol class="dp-xml"><li class="alt"><span><span>print_r(split("[nt]","我爱n北京t天安门")); </span></span></li></ol>
is not differentiated. Case division: The usage of the spliti statement is the same as above
4. Adjust the regular expression sql_regcase that only supports case sensitivity
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"xuandun"</span><span>; </span></span></li> <li class=""><span>echosql_regcase($name); </span></li> </ol>