<p>ucenter第一天<br /> 1,mysql_connect() <br /> mysql_connect -- 打开一个到 MySQL 服务器的连接<br /> 说明<br /> resource mysql_connect ( [string server [, string username [, string password [, bool <br /> <br /> new_link [, int client_flags]]]]] )<br /> 如果成功则返回一个 MySQL 连接标识,失败则返回 FALSE。 <br /> mysql_connect() 建立一个到 MySQL 服务器的连接。当没有提供可选参数时使用以下默认值:server <br /> <br /> = 'localhost:3306',username = 服务器进程所有者的用户名,password = 空密码。 <br /> server 参数可以包括端口号。例如 &quot;hostname:port&quot; 或者是到本地套接字的路径,例如本机上的 <br /> <br /> &quot;:/path/to/socket&quot;。 <br /> 注: 无论指定 &quot;localhost&quot; 或者 &quot;localhost:port&quot; 作为 server,MySQL 客户端库将覆盖之并尝试连<br /> <br /> 接到本地套接字(Windows 中的名字管道)。如果希望使用 TCP/IP 连接,用 &quot;127.0.0.1&quot; 替代 <br /> <br /> &quot;localhost&quot;。如果 MySQL 客户端库试图连接到错误的本地套接字,则应该在 PHP 配置中将 <br /> <br /> mysql.default_host 设为正确的路径并使 server 字段为空。 <br /> &quot;:port&quot; 的支持是 PHP 3.0B4 起加入的。 <br /> &quot;:/path/to/socket&quot; 的支持是 PHP 3.0.10 起加入的。 <br /> 可以在函数名前加上 @ 来抑制失败时产生的错误信息。 <br /> <!--p<br--> $link = mysql_connect(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;)<br /> or die(&quot;Could not connect: &quot; . mysql_error());<br /> print (&quot;Connected successfully&quot;);<br /> mysql_close($link);<br /> ?&gt; <br /> <br /> 2,fsockopen()<br /> fsockopen -- Open Internet or Unix domain socket connection <br /> Description<br /> resource fsockopen ( string target [, int port [, int &amp;errno [, string &amp;errstr [, float <br /> <br /> timeout]]]] )<br /> Initiates a socket connection to the resource specified by target. PHP supports targets in <br /> <br /> the Internet and Unix domains as described in 附录 N. A list of supported transports can <br /> <br /> also be retrieved using stream_get_transports(). <br /> 注: If you need to set a timeout for reading/writing data over the socket, use <br /> <br /> stream_set_timeout(), as the timeout parameter to fsockopen() only applies while <br /> <br /> connecting the socket. <br /> fsockopen() returns a file pointer which may be used together with the other file <br /> <br /> functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()). <br /> 例子 1. fsockopen() Example<br /> <br /> <!--p<br--> $fp = fsockopen(&quot;www.example.com&quot;, 80, $errno, $errstr, 30);<br /> if (!$fp) {<br /> echo &quot;$errstr ($errno)<br /> n&quot;;<br /> } else {<br /> $out = &quot;GET / HTTP/1.1rn&quot;;<br /> $out .= &quot;Host: www.example.comrn&quot;;<br /> $out .= &quot;Connection: Closernrn&quot;;<br /> <br /> fwrite($fp, $out);<br /> while (!feof($fp)) {<br /> echo fgets($fp, 128);<br /> }<br /> fclose($fp);<br /> }<br /> ?&gt; <br /> <br /> <br /> 3,gethostbyname() <br /> gethostbyname<br /> gethostbyname -- Get the IP address corresponding to a given Internet host name <br /> Description<br /> string gethostbyname ( string hostname )<br /> Returns the IP address of the Internet host specified by hostname or a string containing <br /> <br /> the unmodified hostname on failure. <br /> <br /> 例子 1. A simple gethostbyname() example<br /> <!--p<br--> $ip = gethostbyname('www.example.com');<br /> echo $ip;<br /> ?&gt; <br /> <br /> 4,file_get_contents() <br /> file_get_contents -- 将整个文件读入一个字符串<br /> 说明<br /> string file_get_contents ( string filename [, bool use_include_path [, resource context [, <br /> <br /> int offset [, int maxlen]]]] )<br /> 和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的<br /> <br /> 位置开始读取长度为 maxlen 的内容。如果失败,file_get_contents() 将返回 FALSE。 <br /> file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还<br /> <br /> 会使用内存映射技术来增强性能。<br /> 注: 如果要打开有特殊字符的 URL (比如说有空格),就需要使用 urlencode() 进行 URL 编码。 <br /> 注: context 参数可以用 NULL 来忽略。 <br /> <br /> 5,urlencode<br /> urlencode -- 编码 URL 字符串<br /> 描述<br /> string urlencode ( string str )<br /> 返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六<br /> <br /> 进制数,空格则编码为加号(+)。此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与 <br /> <br /> application/x-www-form-urlencoded 的媒体类型编码方式一样。由于历史原因,此编码在将空格编码<br /> <br /> 为加号(+)方面与 RFC1738 编码(参见 rawurlencode())不同。此函数便于将字符串编码并将其用<br /> <br /> 于 URL 的请求部分,同时它还便于将变量传递给下一页: <br /> <br /> 6,xml_parser_create() <br /> xml_parser_create -- 建立一个 XML 解析器<br /> 描述<br /> resource xml_parser_create ( [string encoding] <br /> 函数 xml_parser_create() 建立一个新的 XML 解析器并返回可被其它 XML 函数使用的资源句柄。 <br /> 可选参数 encoding 在 PHP 4 中用来指定要被解析的 XML 输入的字符编码方式。PHP 5 开始,自动侦<br /> <br /> 测输入的 XML 的编码,因此 encoding 参数仅用来指定解析后输出数据的编码。在 PHP 4 总,默认输<br /> <br /> 出的编码与输入数据的编码是相同的。如果传递了空字符串,解析器会尝试搜索头 3 或 4 个字节以确<br /> <br /> 定文档的编码。在 PHP 5.0.0 和 5.0.1 总,默认输出的字符编码是 ISO-8859-1,而 PHP 5.0.2 及以<br /> <br /> 上版本是 UTF-8。解析器支持的编码有 ISO-8859-1, UTF-8 和 US-ASCII。<br /> <br /> 7,define<br /> define -- Defines a named constant<br /> <!--p<br--> define(&quot;CONSTANT&quot;, &quot;Hello world.&quot;);<br /> echo CONSTANT; // outputs &quot;Hello world.&quot;<br /> echo Constant; // outputs &quot;Constant&quot; and issues a notice.<br /> <br /> define(&quot;GREETING&quot;, &quot;Hello you.&quot;, true);<br /> echo GREETING; // outputs &quot;Hello you.&quot;<br /> echo Greeting; // outputs &quot;Hello you.&quot;<br /> ?&gt; <br /> <br /> 8,error_reporting<br /> error_reporting -- Sets which PHP errors are reported<br /> <!--p<br--> // Turn off all error reporting<br /> error_reporting(0);<br /> // Report simple running errors<br /> error_reporting(E_ERROR | E_WARNING | E_PARSE);<br /> // Reporting E_NOTICE can be good too (to report uninitialized<br /> // variables or catch variable name misspellings ...)<br /> error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);<br /> // Report all errors except E_NOTICE<br /> // This is the default value set in php.ini<br /> error_reporting(E_ALL ^ E_NOTICE);<br /> // Report all PHP errors (bitwise 63 may be used in PHP 3)<br /> error_reporting(E_ALL);<br /> // Same as error_reporting(E_ALL);<br /> ini_set('error_reporting', E_ALL);<br /> ?&gt; <br /> <br /> 9,explode<br /> explode -- 使用一个字符串分割另一个字符串<br /> 描述<br /> array explode ( string separator, string string [, int limit] )<br /> 此函数返回由字符串组成的数组,每个元素都是 string 的一个子串,它们被字符串 separator 作为<br /> <br /> 边界点分割出来。如果设置了 limit 参数,则返回的数组包含最多 limit 个元素,而最后那个元素将<br /> <br /> 包含 string 的剩余部分。 <br /> 如果 separator 为空字符串(&quot;&quot;),explode() 将返回 FALSE。如果 separator 所包含的值在 <br /> <br /> string 中找不到,那么 explode() 将返回包含 string 单个元素的数组。 <br /> 如果 limit 参数是负数,则返回除了最后的 limit 个元素外的所有元素。此特性是 PHP 5.1.0 中新<br /> <br /> 增的。 <br /> <br /> 例子 1. explode() 示例<br /> <br /> <!--p<br--> // 示例 1<br /> $pizza = &quot;piece1 piece2 piece3 piece4 piece5 piece6&quot;;<br /> $pieces = explode(&quot; &quot;, $pizza);<br /> echo $pieces[0]; // piece1<br /> echo $pieces[1]; // piece2<br /> // 示例 2<br /> $data = &quot;foo:*:1023:1000::/home/foo:/bin/sh&quot;;<br /> list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(&quot;:&quot;, $data);<br /> echo $user; // foo<br /> echo $pass; // *<br /> ?&gt; <br /> <br /> 例子 2. limit 参数示例<br /> <br /> <!--p<br--> $str = 'one|two|three|four';<br /> // 正数的 limit<br /> print_r(explode('|', $str, 2));<br /> // 负数的 limit<br /> print_r(explode('|', $str, -1));<br /> ?&gt; <br /> <br /> 10,set_magic_quotes_runtime<br /> set_magic_quotes_runtime -- Sets the current active configuration setting of <br /> <br /> magic_quotes_runtime <br /> Description<br /> bool set_magic_quotes_runtime ( int new_setting )<br /> Set the current active configuration setting of magic_quotes_runtime (0 for off, 1 for <br /> <br /> on). <br /> </p>
T:0.004110s,M:247.69 KB
返回顶部 留言