作者 lyh

gx

@@ -435,14 +435,12 @@ function isEnglish($str) { @@ -435,14 +435,12 @@ function isEnglish($str) {
435 * @method :post 435 * @method :post
436 * @time :2023/6/28 17:39 436 * @time :2023/6/28 17:39
437 */ 437 */
438 -function characterTruncation($string,$startTag,$endTag){  
439 - $startPos = strpos($string, $startTag);  
440 - $endPos = strpos($string, $endTag);  
441 - if ($startPos !== false && $endPos !== false) {  
442 - $startPos += strlen($startTag);  
443 - $result = substr($string, $startPos, $endPos - $startPos); 438 +function characterTruncation($string,$pattern){
  439 + preg_match($pattern, $string, $matches);
  440 + if (isset($matches[1])) {
  441 + $result = $matches[1];
  442 + return $result; // 输出:这是footer标签的内容
444 } else { 443 } else {
445 - echo "无法找到起始或结束标签"; 444 + return "未找到匹配的footer标签";
446 } 445 }
447 - return $result;  
448 } 446 }
@@ -106,12 +106,12 @@ class BTemplateLogic extends BaseLogic @@ -106,12 +106,12 @@ class BTemplateLogic extends BaseLogic
106 ] 106 ]
107 ); 107 );
108 //字符串截取 108 //字符串截取
109 - $this->param['head_html'] = characterTruncation($this->param['html'],'<header>','</header>');  
110 - $this->param['main_html'] = characterTruncation($this->param['html'],'<main>','</main>');  
111 - $this->param['footer_html'] = characterTruncation($this->param['html'],'<footer>','</footer>');  
112 - $this->param['head_css'] = characterTruncation($this->param['html'],'<style id="vvvebjs-header">','</style>');  
113 - $this->param['main_css'] = characterTruncation($this->param['html'],'<style id="vvvebjs-style">','</style>');  
114 - $this->param['footer_css'] = characterTruncation($this->param['html'],'<style id="vvvebjs-footer">','</style>'); 109 + $this->param['head_html'] = characterTruncation($this->param['html'], '/<header[^>]*>(.*?)<\/header>/');
  110 + $this->param['main_html'] = characterTruncation($this->param['html'], '/<main[^>]*>(.*?)<\/main>/');
  111 + $this->param['footer_html'] = characterTruncation($this->param['html'], '/<footer[^>]*>(.*?)<\/footer>/');
  112 + $this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/style>/');
  113 + $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-style">(.*?)<\/style>/');
  114 + $this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-footer">(.*?)<\/style>/');
115 if($info === false){ 115 if($info === false){
116 $this->param['project_id'] = $this->user['project_id']; 116 $this->param['project_id'] = $this->user['project_id'];
117 $rs = $this->model->add($this->param); 117 $rs = $this->model->add($this->param);