PHP Daily Practical Tips

Source: Internet
Author: User
Tags add chr empty ftp header ranges return
1. Easy to judge the legality of IP address
The regular judgment of 2.email
3. Examples of whether IP addresses and mask are legitimate
4. About the form refresh
5. About the form refresh

1. Easy to judge the legality of IP address
if (!strcmp (Long2ip (sprintf ("%u", Ip2long ($IP)), $IP)) echo "is IPN";
----
The regular judgment of 2.email
Eregi ("^[_.0-9a-za-z-]+@" ([0-9a-za-z][0-9a-za-z_-]+.) +[a-za-z]$ ", $email);
----
3. Examples of whether IP addresses and mask are legitimate
$ip = ' 192.168.0.84 ';
$mask = ' 255.255.255.0 ';
$network = ' 192.168.0 ';

$ip = Ip2long ($IP);
$mask = Ip2long ($mask);
$network = Ip2long ($network);

if ($ip & $mask) = = $network) echo "Valid IP and MASKN";
?>
----
4. Solved a big depressing problem today
IPB Add user page toadduser.php appears to be repeated, resulting in the addition of new users always reported that the user already exists ... I have been depressed for 3 days, and finally done, great satisfaction!
----
5. About the form refresh
Q: Why did I click on the Back button of the browser and all the fields were emptied?

A: This is because you used the Session_Start function in your form submission page. This function forces the current page to not be cached. The solution is to add the header ("Cache-control:private") after your session_start function; Note that your PHP program cannot have any output before the bank.

Add: There is also a session based solution, preceded by the Session_Start
Session_cache_limiter (' NoCache ');/clear the form
Session_cache_limiter (' private '); Do not empty the form, only during session effective
Session_cache_limiter (' public '); Do not empty the form, as if not using the session general

can be Session_Start (), preceded by Session_cache_limiter ("private,max-age=10800");

Excerpt from Phpe.net
----
6. Quick fix file download head output

Header ("Content-type:application/x-download");
Header ("content-disposition:attachment; Filename= $file _download_name; ");
Header ("Accept-ranges:bytes");
Header ("Content-length: $download _size");
echo ' xxx '

....... 2004-08-19 11:50:30
----
7. Use header output FTP download mode, and support the continuation of the breakpoint
An example:
Header (' Pragma:public ');
Header (' cache-control:private ');
Header (' Cache-control:no-cache, Must-revalidate ');
Header (' accept-ranges:bytes ');
Header (' Connection:close ');
Header ("Content-type:audio/mpeg");

Header ("location:ftp://download:1bk3l4s3k9s2@218.30.116.103/1001/curry chili/curry pepper. rmvb");
....... 2004-10-08 13:26:45
8. Replace all characters with *
$a = "~!@#$%^&*./=-";
Echo preg_replace ("/./", "*", $a);
With Perl's regular replacement, it's convenient
9. Regular matching Chinese
Ereg ("^[". Chr (0XA1). " -". Chr (0xFF)."] +$ ", $STR);
10. Bulk replacement of hyperlinks inside the text
<?php
function Urlparse ($str = ')
{
if (' = = $str ') return $str;

$types = Array ("http", "FTP", "https");

$replace = <<<eophp
' <a href= '. Htmlentities (' \1 '). Htmlentities (' \2 '). " > '. Htmlentities (' \1 '). Htmlentities (' \2 '). ' </a> '
eophp;

$ret = $str;

while (the list (, $type) = each ($types))
{
$ret = Preg_replace ("| $type://) ([^\s]*) |ie ", $replace, $ret);
}

return $ret;
}
?>


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.