怎么自己免费创建网站,如何在网上创建网站

2023-9-30 16:38| 发布者:网赚吧顾问| 查看:7| 评论:0

摘要:  这样做的原因是,,为了避免不耐烦,分成几章来解释,。         三种方式:         1.动态网站,静态时直接使用file _ get _ contents(' http://ww . ABC.com/about ');获取网页html源码,,然后 ...

  这样做的原因是,为了避免不耐烦,分成几章来解释。   

  

  三种方式:   

  

  1.动态网站静态时直接使用file _ get _ contents(' http://ww . ABC.com/about ');获取网页html源码,然后使用file _ put _ contents(' e : \ web/html/about . HTML ',HTML源码)创建静态文件;   

  

  2.做好静态模板.把标识符添加到模块内容显示的地方。例如,公司产品列表# #产品列表# #,在生成静态时读取模板内容str _ replace(# Product list #,$ prolist,$ mubanner);$prolist是我们在数据库中读到的产品列表;   

  

  3.比较麻烦的是把的说法写在模板里,然后分析,的好处,可以减少后台程序的改动;   

  

  我们主要说第三种方法主要使用,的preg _ match _ all,,的preg _ match效率不高,对于loop作为企业站生成静态页面,使用多次应该就够了。   

  

  preg_match($preg, $str, $match);截取第一个   

  

  preg_match_all($preg, $str, $match);截取所有的   

  

  参数描述:   

  

  1.$preg:常规;搜索的模式   

  

  2.$str:搜索到的字符串;   

  

  3.$match:返回数组;   

  

  例1:截取include/header和include/footer。   

  

  $ str=“{包含/页眉} {包含/页脚}”;   

  

  代码如下:   

  

  $preg='/{include(。*)}/';preg_match_all($preg,$str,$ match);print _ r($ match[1]);   

  

  描述:   

  

  1.常规开局结束于2/内线;   

  

  2.开始标志“{include”和结束标志“}”;   

  

  3.*任何字符都不包括换行符;   

  

  4.(.*)括号和无返回值的区别是:没有返回带有开始和结束标志的数组元素,只有$ match[0]没有1;之后,返回两个数组元素$match[0]不变,$ match[1]没有开始和结束的符号;   

  

  输出:   

  

  数组([0]=包含/页眉[1]=包含/页脚)   

  

  在获得包含的标题底部的文件名后,我们可以直接读取相应的模板并替换它。   

  

  具体操作:   

  

  for($ I=0;$ I=count($ match[1])-1;$i ){//读取对应的模板内容$ thtml=file _ get _ contents($ match[1][$ I]);$str=str_replace($match[0][$i],$thtml,$ str);}   

  

  例2:preg_match截取第一个include标签中的内容(字符串“111”)。   

  

  $ str=' { include } 111 {/include } 222 { include } 333 {/include } ';$preg='/{include}(。*?){ \/include }/s ';preg_match($preg,$str,$ match);print _ r($ match);   

  

  描述:   

  

  1.添加修改器s来强制一行;   

  

  2.*?比例1增加了一个问号。如果没有添加结束标记,将使用字符串的最后一次出现;   

  

  3.$match[0]包含开始和结束标志;$ match[1]不存在;   

  

例二输出结果:

  

Array( [0] => {include} 111 {/include} [1] => 111)

  

例3:

  

$str='阿斯顿开好会加速的和卡{cmlist "t":"web_pic","f":"pic_path","c":"pic_cat=3","o":"sort desc,id desc","l":"10","name":"a"}这是要截取的字符串1{/cmlist}大豪科技阿斯顿开好会加速的和卡{cmlist "t":"web_page","f":"page_content","c":"id=80","o":"","name":"a"}这是要截取的字符串2{/cmlist}大豪科技';

  

截取cmlist 中的参数还有 这是要截取的字符串1 这是要截取的字符串2

  

$preg="/{cmlist(.*?)}(.*?){\/cmlist}/is";preg_match_all($preg, $str, $match);print_r($match[1]);

  

说明:

  

1. 这里用到了修饰符i和 s因为给出来的$str是换行的加上修饰符s可以把字符串当成一行来匹配i不区分大小写例如:CMLIST 和cmlist是一个效果;

  

2. 结束标志包含了“/”需要转义前边加上“\”;

  

3. $match[1]是截取到的参数$match[2]是我们截取到的字符串;

  

$match[1]输出结果:

  

Array( [0] => "t":"web_pic","f":"pic_path","c":"pic_cat=3","o":"sort desc,id desc","l":"10","name":"a" [1] => "t":"web_page","f":"page_content","c":"id=80","o":"","name":"a")

  

$match[2]输出结果:

  

Array( [0] => 这是要截取的字符串1 [1] => 这是要截取的字符串2)

  

查看$match[1]输出结果我们会发现和json格式很像只是2边差了花括号{}我们手动补充上。

  

具体操作:

  

for($i=0;$i<=count($match[1])-1;$i++){ echo="" json_decode("{".$match[1][$i]."}")-="">t; exit;}

  

输出结果:web_pic

  

上边是转成了对象也可以转成数组。

  

for($i=0;$i<=count($match[1])-1;$i++){ print_r(="" json_decode("{".$match[1][$i]."}",true));="">

  

输出结果:

  

Array( [t] => web_pic [f] => pic_path [c] => pic_cat=3 [o] => sort desc,id desc [l] => 10 [name] => a)

  

可以和tp的查询语句一一对应

  

$list=Db::name(t)->field(f)->where(c)->order(o)->limit(l)->select();

  

foreach($list as $$name){}

  

例4:

  

$str='{cmlist "t":"web_cat","f":"cat_name,cat_html_path,cat_html_name","c":"parentid=0 and projectid=81","o":"sort desc,id desc","l":"","name":"a"}{fa cat_name|}{/cmlist}';

  

1. 要截取cat_html_path、cat_html_name、cat_name;

  

2. 竖线分隔definefuc为自定义函数名称左侧为参数变量参数为常量放到右边(conststr对应funcname对应函数名称);

  

3. fa中的a是动态地对应了cmlist中的name;

  

4. 如果name:a对应fa如果name:aa对应的是faa;

  

5. 按照例2中的方法在for循环中再次截取 以{fa开头以}结尾就得到了我们想要的字符串这些字符串对应了表的字段。

  

6. $match[2]是我们要重新截取的原字符串;

  

操作如下:

  

for($i=0;$i<=count($match[1])-1;$i++){ $name="json_decode("{".$match[1][$i]."}")-">name;$fielpreg="/{f".$name."(.*?)}/"; preg_match_all($fielpreg, $match[2][$i], $fiearr); //$fiearr就是我们得到的字段的数组 print_r( $fiearr[1]); exit; }

  

输出结果:

  

Array( [0] => cat_html_path,cat_html_name|"funcname":"definefuc","conststr":"1" [1] => cat_html_name [2] => cat_name)

  

使用for循环得到value值“|”分割数组判断是否包含自定义函数;

  

for($i=0;$i<=count($match[1])-1;$i++){ $name="json_decode("{".$match[1][$i]."}")-">name; $fielpreg="/{f".$name."(.*?)}/"; preg_match_all($fielpreg, $match[2][$i], $fiearr); for($z=0;$z<=count($fiearr[1])-1;$z++){$isarr=explode("|",$fiearr[1][$z]); 存在自定义方法if(count($isarr)="">1){ $funcname=json_decode("{".$isarr[1]."}")->funcname; $conststr=json_decode("{".$isarr[1]."}")->conststr; $fiar=explode(",",$fiearr[0]); //可以是多个变量合并成了字符串 $fistr=""; for($c=0;$c<=count($fiar)-1;$c++){ $fistr.="$$name[$fiar[$c]].",";" }="" 左侧参数="" $fistr="" 右侧常量参数$conststr="" $fistr="mb_substr($fistr,0,mb_strlen($fistr)-1);" $str="str_replace($fiearr[0][$i],$funcname($fistr,$conststr),$str);}else{">$str=str_replace($fiearr[0][$i],$$name[$fiearr[1][$z]],$str);}}}

  

注意:

  

传递的变量参数多个参数实际是一个字符串在我们自定义方法内使用该参数的时候应该是先分割成数组单个参数没有影响。

  

鲜花

握手

雷人

路过

鸡蛋

最新评论

相关分类

图文热点

热门推荐

返回顶部 关注微信 下载APP