日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php替换文件中的数据库,批量替换php文件中的class,id的值

發布時間:2025/3/20 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php替换文件中的数据库,批量替换php文件中的class,id的值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

批量替換php文件中的class,id的值

$val="wqewq

替換成"wqewq

//其實也就是在class,id值后面加上一個字符串

//我要替換的是文件里的。所以要從文件讀取出來

//我自己寫了一個但是不行類似這樣

$fp=fopen("tpl_checkout_stacked.php","rb");

$content=fread($fp,filesize("tpl_checkout_stacked.php"));

$content=ereg_replace(" id='(.*)'"," id='\\1_test'",$content);

$content=ereg_replace(" class='(.*)'"," class='\\1_test'",$content);

echo($content);

fclose($fp);

$fp=fopen("test.php","a");

fwrite($content,$fp);

$filepath = '/path/to/file';

$content = file_get_contents($filepath);

替換

file_put_contents($filepath, $content);

// +------ 我以前寫的一個替換函數

function file_modify($search_contents, $replace_contents, $filename)

{

$fp = file_get_contents($filename);

$new_fp = str_replace($search_contents, $replace_contents, $fp);

file_put_contents($filename, $new_fp);

}

// +------ 用法

file_modify('sdf hjhj', 'sdf_test hjhj_test', 'test10.html');

preg_replace("/(class='([^\s]+)\s+([^']+)/gi","class='$1_test $2_test'",$content);

preg_replace("/id='([^\s]+)\s+([^']+)/","id='$1_test $2_test'",$content);

總結

以上是生活随笔為你收集整理的php替换文件中的数据库,批量替换php文件中的class,id的值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。