Home Backend Development PHP Tutorial How to replace relative addresses with absolute addresses in batches (implemented using bat batch processing)_PHP tutorial

How to replace relative addresses with absolute addresses in batches (implemented using bat batch processing)_PHP tutorial

Jul 21, 2016 pm 03:10 PM
bat sta url for use address how accomplish Batch processing batch yes replace relatively absolute path Link

If your URL link is a relative path "static/mapi.css", you want to replace it in batches with an absolute path "http://dev.baidu.com/wiki/static/map/cloud/static/mapi.css" . Then, you can do this:

Write a PHP file and write the URL that needs to be replaced.
The meaning of this code is to replace #BASE_URL# with http://api.map.baidu.com/lbsapi/cloud/.
What this sentence means is to replace the content in the resource file and then put it in the cloud folder. FileUtil::copyDir("resource","cloud",true);

Copy code The code is as follows:

< ?php
//Keywords that need to be replaced
$GLOBALS["patterns"] = array(
"/#BASE_URL#/"
);
//Replaced content, Corresponds one-to-one with the above matching rules
$GLOBALS["replacements"] = array(
"http://api.map.baidu.com/lbsapi/cloud/"
//"http: //172.22.168.178/lbsapi/"
//"http://dev.baidu.com/wiki/static/map/cloud/"
);
/**
* Manipulate file classes
*
* Example:
* FileUtil::copyDir('b','d/e'); Test copying the folder to create a d/e folder, and put Copy the contents of the b folder into it
* FileUtil::copyFile('b/1/2/3.exe','b/b/3.exe'); Test copying files to create a b/b folder , and copy the 3.exe file in the b/1/2 folder
* FileUtil::createDir('a/1/2/3'); Test to create a folder and create a/1/2/ 3 Folder
* FileUtil::unlinkFile('b/d/3.exe'); Test deletion of file Delete b/d/3.exe file
*/
class FileUtil {
/**
* Create folder
*
* @param string $aimUrl
* @return viod
*/
function createDir($aimUrl) {
$aimUrl = str_replace('', '/', $aimUrl);
$ aimDir = '';
$arr = explode('/', $aimUrl);
foreach ($arr as $str) {
$aimDir .= $str . '/';
if (!file_exists($aimDir)) {
mkdir($aimDir);
}
}
}
/**
* Delete file
*
* @param string $aimUrl
* @return boolean
*/
function unlinkFile($aimUrl ) {
if (file_exists($aimUrl)) {
unlink($aimUrl);
return true;
} else {
return false;
}
}
/**
* Copy folder
*
* @param string $oldDir
* @param string $aimDir
* @param boolean $overWrite This parameter controls whether to overwrite the original file
* @ return boolean
*/
function copyDir($oldDir, $aimDir, $overWrite = false) {
$aimDir = str_replace('', '/', $aimDir);
$aimDir = substr($aimDir, -1) == '/' ? $aimDir : $aimDir.'/';
$oldDir = str_replace('', '/', $oldDir);
$ oldDir = substr($oldDir, -1) == '/' ? $oldDir : $oldDir.'/';
if (!is_dir($oldDir)) {
return false;
}
if (!file_exists($aimDir)) {
FileUtil::createDir($aimDir);
}
$dirHandle = opendir($oldDir);
while(false !== ( $file = readdir($dirHandle))) {
if ($file == '.' || $file == '..') {
continue;
}
if (! is_dir($oldDir . $file)) {
FileUtil::copyFile($oldDir . $file, $aimDir . $file, $overWrite);
} else {
FileUtil::copyDir($oldDir . $file, $aimDir . $file, $overWrite);
}
}
return closedir($dirHandle);
}
/**
* Copy file
*
* @param string $fileUrl
* @param string $aimUrl
* @param boolean $overWrite This parameter controls whether to overwrite the original file
* @return boolean
*/
function copyFile($fileUrl, $aimUrl, $overWrite = false) {
if (!file_exists($fileUrl)) {
return false;
}
if (file_exists($aimUrl) && $ overWrite == false) {
return false;
} elseif (file_exists($aimUrl) && $overWrite == true) {
FileUtil::unlinkFile($aimUrl);
}
$aimDir = dirname($aimUrl);
FileUtil::createDir($aimDir);
copy($fileUrl, $aimUrl);
//Replacement variables
$apiFilePointer = fopen($aimUrl , 'r');
$apiFileContent = fread($apiFilePointer, filesize($aimUrl));
//Only replace js, html, css files
if (preg_match('/(. js|.html|.css|.htm)$/', $aimUrl)) {
$apiFileContent = preg_replace($GLOBALS["patterns"], $GLOBALS["replacements"], $apiFileContent);
}
fclose($apiFilePointer);
echo $aimUrl."rn";
$apiFilePointer = fopen($aimUrl, 'w+');
fwrite($apiFilePointer, $apiFileContent);
fclose($apiFilePointer);
//Replacement variable
return true;
}
}
FileUtil::copyDir("resource","cloud",true);
?>

Write another bat batch file to run this PHP.
php release.php
Now, just click on the bat file, and the relative addresses in all pages will become absolute addresses.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327111.htmlTechArticleIf your url link is a relative path "static/mapi.css", you want to replace it in batches with absolute Path "http://dev.baidu.com/wiki/static/map/cloud/static/mapi.css". Well, you can...
Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to download links starting with 115://? Download method introduction How to download links starting with 115://? Download method introduction Mar 14, 2024 am 11:58 AM

Recently, many users have been asking the editor, how to download links starting with 115://? If you want to download links starting with 115://, you need to use the 115 browser. After you download the 115 browser, let's take a look at the download tutorial compiled by the editor below. Introduction to how to download links starting with 115:// 1. Log in to 115.com, download and install the 115 browser. 2. Enter: chrome://extensions/ in the 115 browser address bar, enter the extension center, search for Tampermonkey, and install the corresponding plug-in. 3. Enter in the address bar of 115 browser: Grease Monkey Script: https://greasyfork.org/en/

How to get the WeChat video account link? How to add product links to WeChat video account? How to get the WeChat video account link? How to add product links to WeChat video account? Mar 22, 2024 pm 09:36 PM

As part of the WeChat ecosystem, WeChat video accounts have gradually become an important promotion tool for content creators and merchants. Getting links to video accounts on this platform is crucial for sharing and disseminating content. The following will introduce in detail how to obtain the WeChat video account link and how to add product links to the video account to improve the dissemination effect of the content. 1. How to get the WeChat video account link? After posting a video on your WeChat video account, the system will automatically create a video link. Authors can copy the link after publishing to facilitate sharing and dissemination. After logging in to your WeChat video account, you can browse the homepage of your video account. On the home page, each video is accompanied by a corresponding link so you can copy or share it directly. 3. Search video account: Enter the video account name in the WeChat search box

Why NameResolutionError(self.host, self, e) from e and how to solve it Why NameResolutionError(self.host, self, e) from e and how to solve it Mar 01, 2024 pm 01:20 PM

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

What are the requirements for a video link? How to link the video account with goods? What are the requirements for a video link? How to link the video account with goods? Mar 07, 2024 pm 01:13 PM

With the popularity of short video platforms, more and more creators are beginning to use video accounts to create and promote content. Video accounts can not only showcase personal talents, but also realize commercial monetization through product links. However, to add a link to a video account, certain conditions must be met. 1. What are the requirements for a video link? Video account authentication is a prerequisite for adding links to your video account. Currently, major short video platforms such as Douyin and Kuaishou provide certification services, which mainly include two types: personal certification and institutional certification. Personal certification requires the submission of real identity information, while institutional certification requires the provision of certification materials from relevant companies or organizations. After completing the authentication, users can add links to their video accounts to enhance the credibility and authority of their accounts. One of the video link

What is the difference between html and url What is the difference between html and url Mar 06, 2024 pm 03:06 PM

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

Where can I change my Meituan address? Meituan address modification tutorial! Where can I change my Meituan address? Meituan address modification tutorial! Mar 15, 2024 pm 04:07 PM

1. Where can I change my Meituan address? Meituan address modification tutorial! Method (1) 1. Enter Meituan My Page and click Settings. 2. Select personal information. 3. Click the shipping address again. 4. Finally, select the address you want to modify, click the pen icon on the right side of the address, and modify it. Method (2) 1. On the homepage of the Meituan app, click Takeout, then click More Functions after entering. 2. In the More interface, click Manage Address. 3. In the My Shipping Address interface, select Edit. 4. Modify them one by one according to your needs, and finally click to save the address.

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

See all articles