⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strreplace.class.php

📁 Phpcms2008 是一款基于 PHP+Mysql 架构的网站内容管理系统
💻 PHP
字号:
<?php
class strreplace
{
	var $db;
	var $lang;
	var $mod;
	var $file;

    function __construct()
	{
		global $db,$LANG,$mod,$file;
		$this->db = &$db;
		$this->lang = $LANG;
		$this->mod = $mod;
		$this->file = $file;
	}

	function strreplace()
	{
		$this->__construct();
	}

	function replaceall($fromtable,$fromfield1,$condition,$type,$search,$replace,$addstr)
	{
		if(empty($fromtable))
		{
			showmessage($this->lang['the_datatable_to_replace_cannot_null']);
		}
		if(empty($fromfield1))
		{
			showmessage($this->lang['the_field_to_replace_cannot_null']);
		}
		$result = $this->db->query("SHOW COLUMNS FROM `$fromtable`");
		while($r = $this->db->fetch_array($result))
		{
			if($r['Key'] == 'PRI')
			{
				$priid = $r['Field'];
				break;
			}
		}
		$this->db->free_result($result);
		if(!$priid) showmessage($this->lang['no_primary_key_int_this_table']);
		$condition = $condition ? 'where '.stripslashes($condition) : '';

		if($type==1) //replace
		{

			if(empty($search))
			{
				showmessage($this->lang['the_content_to_replace_cannot_null']);
			}
            $sql = "UPDATE `$fromtable` SET `$fromfield1` = REPLACE($fromfield1,'$search','$replace')  $condition";
			$result = $this->db->query($sql);
			$this->db->free_result($result);
			showmessage($this->lang['replace_success']);
		}
		elseif($type==2) //ubb
		{
			if(empty($condition))
			{
				showmessage('鏇挎崲鏉′欢涓嶈兘涓虹┖');
			}
			require PHPCMS_ROOT.'include/ubb.func.php';
			$result = $this->db->query("SELECT `$fromfield1`,`$priid` FROM `$fromtable` $condition ");
			while($r = $this->db->fetch_array($result))
			{
				$r[$fromfield1] = ubb($r[$fromfield1]);
				$r[$fromfield1] = addslashes($r[$fromfield1]);
				$this->db->query("UPDATE `$fromtable` SET `$fromfield1` = '".$r[$fromfield1]."' WHERE $priid='".$r[$priid]."'");
			}
			$this->db->free_result($result);
			showmessage($this->lang['ubb_replace_success']);
		}
		elseif($type==3) // add on front
		{
			if(empty($addstr))
			{
				showmessage($this->lang['prefix_of_content_not_null']);
			}
			$result = $this->db->query("SELECT $fromfield1,$priid FROM $fromtable $condition ");
			while($r = $this->db->fetch_array($result))
			{
				$r[$fromfield1] = $addstr.$r[$fromfield1];
				$r[$fromfield1] = addslashes($r[$fromfield1]);
				$this->db->query("UPDATE `$fromtable` SET `$fromfield1` = '".$r[$fromfield1]."' WHERE `$priid` ='".$r[$priid]."'");
			}
			$this->db->free_result($result);
			showmessage($this->lang['replace_success']);
		}
		elseif($type==4) // add on front
		{
			if(empty($addstr))
			{
				showmessage($this->lang['extention_of_content_not_null']);
			}
			$result = $this->db->query("SELECT `$fromfield1`,`$priid` FROM `$fromtable` $condition ");
			while($r = $this->db->fetch_array($result))
			{
				$r[$fromfield1] = $r[$fromfield1].$addstr;
				$r[$fromfield1] = addslashes($r[$fromfield1]);
				$this->db->query("UPDATE `$fromtable` SET `$fromfield1` ='".$r[$fromfield1]."' WHERE $priid='".$r[$priid]."'");
			}
			$this->db->free_result($result);
			showmessage($this->lang['replace_success']);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -