search
Homephp教程php手册php模块参考,php

php模块参考,php

<span><span>  1</span> <?<span>php
</span><span>  2</span> <span>//</span><span>数据库连接类</span>
<span>  3</span> <span>class</span><span> ConnDB{
</span><span>  4</span>     
<span>  5</span>     <span>var</span> <span>$dbtype</span><span>;
</span><span>  6</span>     <span>var</span> <span>$host</span><span>;
</span><span>  7</span>     <span>var</span> <span>$user</span><span>;
</span><span>  8</span>     <span>var</span> <span>$pwd</span><span>;
</span><span>  9</span>     <span>var</span> <span>$dbname</span><span>;
</span><span> 10</span>     
<span> 11</span>     <span>//</span><span>构造方法</span>
<span> 12</span>     <span>function</span> ConnDB(<span>$dbtype</span>,<span>$host</span>,<span>$user</span>,<span>$pwd</span>,<span>$dbname</span><span>){
</span><span> 13</span>         <span>$this</span>->dbtype=<span>$dbtype</span><span>;
</span><span> 14</span>         <span>$this</span>->host=<span>$host</span><span>;
</span><span> 15</span>         <span>$this</span>->user=<span>$user</span><span>;
</span><span> 16</span>         <span>$this</span>->pwd=<span>$pwd</span><span>;
</span><span> 17</span>         <span>$this</span>->dbname=<span>$dbname</span><span>;
</span><span> 18</span> <span>    }
</span><span> 19</span> 
<span> 20</span>     <span>//</span><span>实现数据库的连接并返回连接对象</span>
<span> 21</span>     <span>function</span><span> GetConnId(){
</span><span> 22</span>          
<span> 23</span>         <span>if</span>(<span>$this</span>->dbtype=="mysql" || <span>$this</span>->dbtype=="mssql"<span>){
</span><span> 24</span>             <span>$dsn</span>="<span>$this</span>->dbtype:host=<span>$this</span>->host;dbname=<span>$this</span>->dbname"<span>;
</span><span> 25</span>         }<span>else</span><span>{
</span><span> 26</span>             <span>$dsn</span>="<span>$this</span>->dbtype:dbname=<span>$this</span>->dbname"<span>;
</span><span> 27</span> <span>        }    
</span><span> 28</span>         <span>try</span><span> {
</span><span> 29</span>             <span>$conn</span> = <span>new</span> PDO(<span>$dsn</span>, <span>$this</span>->user, <span>$this</span>->pwd);     <span>//</span><span>初始化一个PDO对象,就是创建了数据库连接对象$pdo</span>
<span> 30</span>             <span>$conn</span>->query("set names utf8"<span>);
</span><span> 31</span>             <span>return</span> <span>$conn</span><span>;
</span><span> 32</span>         } <span>catch</span> (PDOException <span>$e</span><span>) {
</span><span> 33</span>             <span>die</span> ("Error!: " . <span>$e</span>->getMessage() . "<br/>"<span>);
</span><span> 34</span> <span>        }
</span><span> 35</span> 
<span> 36</span>          
<span> 37</span> <span>    }    
</span><span> 38</span> <span>}
</span><span> 39</span> 
<span> 40</span> <span>//</span><span>数据库管理类</span>
<span> 41</span> <span>class</span><span> AdminDB{
</span><span> 42</span>     
<span> 43</span>     
<span> 44</span>     <span>function</span> ExecSQL(<span>$sqlstr</span>,<span>$conn</span><span>){
</span><span> 45</span>         
<span> 46</span>         <span>$sqltype</span>=<span>strtolower</span>(<span>substr</span>(<span>trim</span>(<span>$sqlstr</span>),0,6<span>));
</span><span> 47</span>         <span>$rs</span>=<span>$conn</span>->prepare(<span>$sqlstr</span>);        <span>//</span><span>准备查询语句</span>
<span> 48</span>         <span>$rs</span>->execute();                    <span>//</span><span>执行查询语句,并返回结果集</span>
<span> 49</span>         <span>if</span>(<span>$sqltype</span>=="select"<span>){
</span><span> 50</span>             <span>$array</span>=<span>$rs</span>->fetchAll(PDO::FETCH_ASSOC);        <span>//</span><span>获取结果集中的所有数据</span>
<span> 51</span>             <span>if</span>(<span>count</span>(<span>$array</span>)==0 || <span>$rs</span>==<span>false</span><span>)
</span><span> 52</span>                 <span>return</span> <span>false</span><span>;
</span><span> 53</span>             <span>else</span>
<span> 54</span>                 <span>return</span> <span>$array</span><span>;
</span><span> 55</span>         }<span>elseif</span> (<span>$sqltype</span>=="update" || <span>$sqltype</span>=="insert" || <span>$sqltype</span>=="delete"<span>){            
</span><span> 56</span>             <span>if</span>(<span>$rs</span><span>)
</span><span> 57</span>                 <span>return</span> <span>true</span><span>;
</span><span> 58</span>             <span>else</span> 
<span> 59</span>                 <span>return</span> <span>false</span><span>;    
</span><span> 60</span> <span>        }
</span><span> 61</span> <span>    }
</span><span> 62</span> <span>}
</span><span> 63</span> <span>//</span><span>分页类</span>
<span> 64</span> <span>class</span><span> SepPage{
</span><span> 65</span>     <span>var</span> <span>$rs</span><span>;
</span><span> 66</span>     <span>var</span> <span>$pagesize</span><span>;
</span><span> 67</span>     <span>var</span> <span>$nowpage</span><span>;
</span><span> 68</span>     <span>var</span> <span>$array</span><span>;
</span><span> 69</span>     <span>var</span> <span>$conn</span><span>;
</span><span> 70</span>     <span>var</span> <span>$sqlstr</span><span>;
</span><span> 71</span>     <span>function</span> ShowData(<span>$sqlstr</span>,<span>$conn</span>,<span>$pagesize</span>,<span>$nowpage</span>){    <span>//</span><span>定义方法</span>
<span> 72</span>         <span>if</span>(!<span>isset</span>(<span>$nowpage</span>) || <span>$nowpage</span>=="")            <span>//</span><span>判断变量值是否为空</span>
<span> 73</span>             <span>$this</span>->nowpage=1;                        <span>//</span><span>定义每页起始页</span>
<span> 74</span>         <span>else</span>
<span> 75</span>             <span>$this</span>->nowpage=<span>$nowpage</span><span>;
</span><span> 76</span>         <span>$this</span>->pagesize=<span>$pagesize</span>;                    <span>//</span><span>定义每页输出的记录数</span>
<span> 77</span>         <span>$this</span>->conn=<span>$conn</span>;                            <span>//</span><span>连接数据库返回的标识</span>
<span> 78</span>         <span>$this</span>->sqlstr=<span>$sqlstr</span>;                            <span>//</span><span>执行的查询语句</span>
<span> 79</span>         <span>$offset</span>=(<span>$this</span>->nowpage-1)*<span>$this</span>-><span>pagesize;
</span><span> 80</span>         <span>$sql</span>=<span>$this</span>->sqlstr." limit <span>$offset</span>, <span>$this</span>->pagesize"<span>;
</span><span> 81</span>         <span>$result</span>=<span>$this</span>->conn->prepare(<span>$sql</span>);            <span>//</span><span>准备查询语句</span>
<span> 82</span>         <span>$result</span>->execute();                        <span>//</span><span>执行查询语句,并返回结果集</span>
<span> 83</span>         <span>$this</span>-><span>array</span>=<span>$result</span>->fetchAll(PDO::FETCH_ASSOC);        <span>//</span><span>获取结果集中的所有数据</span>
<span> 84</span>         <span>if</span>(<span>count</span>(<span>$this</span>-><span>array</span>)==0 || <span>$this</span>-><span>array</span>==<span>false</span><span>)
</span><span> 85</span>             <span>return</span> <span>false</span><span>;
</span><span> 86</span>         <span>else</span>
<span> 87</span>             <span>return</span> <span>$this</span>-><span>array</span><span>;
</span><span> 88</span> <span>    }
</span><span> 89</span>     
<span> 90</span>     <span>function</span> ShowPage(<span>$contentname</span>,<span>$utits</span>,<span>$anothersearchstr</span>,<span>$anothersearchstrs</span>,<span>$class</span><span>){
</span><span> 91</span>         <span>$str</span>=""<span>;
</span><span> 92</span>         <span>$res</span>=<span>$this</span>->conn->prepare(<span>$this</span>->sqlstr);            <span>//</span><span>准备查询语句</span>
<span> 93</span>         <span>$res</span>->execute();                        <span>//</span><span>执行查询语句,并返回结果集</span>
<span> 94</span>         <span>$this</span>-><span>array</span>=<span>$res</span>->fetchAll(PDO::FETCH_ASSOC);        <span>//</span><span>获取结果集中的所有数据    </span>
<span> 95</span>         <span>$record</span>=<span>count</span>(<span>$this</span>-><span>array</span>);                <span>//</span><span>统计记录总数</span>
<span> 96</span>         
<span> 97</span>         <span>$pagecount</span>=<span>ceil</span>(<span>$record</span>/<span>$this</span>->pagesize);        <span>//</span><span>计算共有几页</span>
<span> 98</span>         <span>$str</span>.=<span>$contentname</span>." ".<span>$record</span>." ".<span>$utits</span>." 每页 ".<span>$this</span>->pagesize." ".<span>$utits</span>." 第 ".<span>$this</span>->nowpage." 页/共 ".<span>$pagecount</span>." 页"<span>;
</span><span> 99</span>         <span>$str</span>.="    "<span>;
</span><span>100</span>         <span>if</span>(<span>$this</span>->nowpage!=1<span>)
</span><span>101</span>             <span>$str</span>.="<a href=".<span>$_SERVER</span>['PHP_SELF']."?page=1&page_type=".<span>$anothersearchstr</span>."&parameter2=".<span>$anothersearchstrs</span>." class=".<span>$class</span>.">首页</a>"<span>;
</span><span>102</span>         <span>else</span>
<span>103</span>             <span>$str</span>.="<font color='#555555'>首页</font>"<span>;
</span><span>104</span>         <span>$str</span>.=" "<span>;
</span><span>105</span>         <span>if</span>(<span>$this</span>->nowpage!=1<span>)
</span><span>106</span>             <span>$str</span>.="<a href=".<span>$_SERVER</span>['PHP_SELF']."?page=".(<span>$this</span>->nowpage-1)."&page_type=".<span>$anothersearchstr</span>."&parameter2=".<span>$anothersearchstrs</span>." class=".<span>$class</span>.">上一页</a>"<span>;
</span><span>107</span>         <span>else</span>
<span>108</span>             <span>$str</span>.="<font color='#555555'>上一页</font>"<span>;
</span><span>109</span>         <span>$str</span>.=" "<span>;    
</span><span>110</span>         <span>if</span>(<span>$this</span>->nowpage!=<span>$pagecount</span><span>)
</span><span>111</span>             <span>$str</span>.="<a href=".<span>$_SERVER</span>['PHP_SELF']."?page=".(<span>$this</span>->nowpage+1)."&page_type=".<span>$anothersearchstr</span>."&parameter2=".<span>$anothersearchstrs</span>." class=".<span>$class</span>.">下一页</a>"<span>;
</span><span>112</span>         <span>else</span>
<span>113</span>             <span>$str</span>.="<font color='#555555'>下一页</font>"<span>;    
</span><span>114</span>         <span>$str</span>.=" "<span>;
</span><span>115</span>         <span>if</span>(<span>$this</span>->nowpage!=<span>$pagecount</span><span>)
</span><span>116</span>             <span>$str</span>.="<a href=".<span>$_SERVER</span>['PHP_SELF']."?page=".<span>$pagecount</span>."&page_type=".<span>$anothersearchstr</span>."&parameter2=".<span>$anothersearchstrs</span>." class=".<span>$class</span>.">尾页</a>"<span>;
</span><span>117</span>         <span>else</span>
<span>118</span>             <span>$str</span>.="<font color='#555555'>尾页</font>"<span>;
</span><span>119</span>         <span>if</span>(<span>count</span>(<span>$this</span>-><span>array</span>)==0 || <span>$this</span>-><span>array</span>==<span>false</span><span>)            
</span><span>120</span>             <span>return</span> "无数据!"<span>;
</span><span>121</span>         <span>else</span>
<span>122</span>             <span>return</span> <span>$str</span><span>;    
</span><span>123</span> <span>    }
</span><span>124</span> <span>}
</span><span>125</span> <span>//</span><span>系统常用方法</span>
<span>126</span> <span>class</span><span> UseFun{
</span><span>127</span>     
<span>128</span>     <span>function</span> UnHtml(<span>$text</span><span>){
</span><span>129</span>        <span>$content</span>=(<span>nl2br</span>(<span>htmlspecialchars</span>(<span>$text</span><span>)));
</span><span>130</span>        <span>$content</span>=<span>str_replace</span>("[strong]","<strong>",<span>$content</span><span>);
</span><span>131</span>        <span>$content</span>=<span>str_replace</span>("[/strong]","</strong>",<span>$content</span><span>);
</span><span>132</span>        <span>$content</span>=<span>str_replace</span>("[em]","<em>",<span>$content</span><span>);
</span><span>133</span>        <span>$content</span>=<span>str_replace</span>("[/em]","</em>",<span>$content</span><span>);
</span><span>134</span>        <span>$content</span>=<span>str_replace</span>("[u]","<u>",<span>$content</span><span>);
</span><span>135</span>        <span>$content</span>=<span>str_replace</span>("[/u]","</u>",<span>$content</span><span>);
</span><span>136</span>     
<span>137</span>     
<span>138</span>        <span>$content</span>=<span>str_replace</span>("[font color=#FF0000]","<font color=#FF0000>",<span>$content</span><span>);
</span><span>139</span>        <span>$content</span>=<span>str_replace</span>("[font color=#00FF00]","<font color=#00FF00>",<span>$content</span><span>);
</span><span>140</span>        <span>$content</span>=<span>str_replace</span>("[font color=#0000FF]","<font color=#0000FF>",<span>$content</span><span>);
</span><span>141</span>     
<span>142</span>        <span>$content</span>=<span>str_replace</span>("[font face=楷体_GB2312]","<font face=楷体_GB2312>",<span>$content</span><span>);
</span><span>143</span>        <span>$content</span>=<span>str_replace</span>("[font face=宋体]","<font face=新宋体>",<span>$content</span><span>);
</span><span>144</span>        <span>$content</span>=<span>str_replace</span>("[font face=隶书]","<font face=隶书>",<span>$content</span><span>);
</span><span>145</span>        <span>$content</span>=<span>str_replace</span>("[/font]","</font>",<span>$content</span><span>);
</span><span>146</span>        <span>//</span><span>$content=str_replace(chr(32)," ",$content);</span>
<span>147</span>        <span>$content</span>=<span>str_replace</span>("[font size=1]","<font size=1>",<span>$content</span><span>);
</span><span>148</span>        <span>$content</span>=<span>str_replace</span>("[font size=2]","<font size=2>",<span>$content</span><span>);
</span><span>149</span>        <span>$content</span>=<span>str_replace</span>("[font size=3]","<font size=3>",<span>$content</span><span>);
</span><span>150</span>        <span>$content</span>=<span>str_replace</span>("[font size=4]","<font size=4>",<span>$content</span><span>);
</span><span>151</span>        <span>$content</span>=<span>str_replace</span>("[font size=5]","<font size=5>",<span>$content</span><span>);
</span><span>152</span>        <span>$content</span>=<span>str_replace</span>("[font size=6]","<font size=6>",<span>$content</span><span>);
</span><span>153</span>        
<span>154</span>        <span>$content</span>=<span>str_replace</span>("[FIELDSET][LEGEND]","<FIELDSET><LEGEND>",<span>$content</span><span>);
</span><span>155</span>        <span>$content</span>=<span>str_replace</span>("[/LEGEND]","</LEGEND>",<span>$content</span><span>);
</span><span>156</span>        <span>$content</span>=<span>str_replace</span>("[/FIELDSET]","</FIELDSET>",<span>$content</span><span>);
</span><span>157</span>        <span>return</span> <span>$content</span><span>;
</span><span>158</span> <span>    }
</span><span>159</span>     
<span>160</span> <span>}
</span><span>161</span> 
<span>162</span> ?></span>

 

问php有什比较流行的模块?

说模块....我太理解,因php模块php环境概念,php环境由多模块组成,模块用来php实现某些功能,比说gd库,用来实现图片操作.

过我觉得说代码块,或者指重用代码,找php类去www.phpclasses.org,官方有2项目,叫PEAR,另外叫PECL,里面提供了大量功能支持,还有兄弟已经入门了,我建议看看zendframework.

已经有的php模块怎使用?是添加到网页?

留言板源码复制web目录下比bbs目录主页面加链接bbs目录下留言程序行
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!