How to delete comments in php

藏色散人
Release: 2023-03-02 06:16:01
Original
2853 people have browsed it

How to delete comments in php: first create a file code for testing; then customize a "removeComment" method; then implement the function of deleting comments through the "preg_replace" function; finally execute this in the browser Just file.

How to delete comments in php

PHP Remove comments in the code

The test file code is as follows:


        
Copy after login

The code to remove the comments is as follows:

/** * Created by PhpStorm. * User: 25754 * Date: 2019/10/17 * Time: 9:54 */ function removeComment($content) { return preg_replace("/(\/\*(\s|.)*?\*\/)|(\/\/.(\s|.*))|(#(\s*)?(.*))/", '', str_replace(array("\r\n", "\r"), "\n", $content)); } $content = file_get_contents("./test.php"); echo removeComment($content);
Copy after login

The result code is as follows:

$a = 1; $b = 2; $c = $a+$b; function sum($a, $b) { return $a + $b; } $a = 1; $b = 2; $c = $a * $b; $usedFuncs = "abcd"; preg_split("
Copy after login

For a lot of related knowledge, please visitPHP Chinese website!

The above is the detailed content of How to delete comments in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!