Home > Backend Development > PHP Tutorial > About the method of subtracting strings in disguised form in PHP

About the method of subtracting strings in disguised form in PHP

不言
Release: 2023-04-01 17:00:01
Original
2306 people have browsed it

This article mainly introduces the disguised string subtraction method in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

Very extreme example, one Record the ideas for solving problems in disguised form for later use.
How to remove the suffix from the default file name?

  $fileName = a.txt
Copy after login

Two methods:
1: Borrow PHP's strrchr trim method: strrchr(string1, string2) returns the part from the end of string1 to the first encounter with string2, together with string2 Return together.
The suffix is ​​generally . Position, substr(string1,num1,num2) intercepts string1 strings from num1 to num2.
Also with the help of "."

$str1 = strrchr($fileName,"."); 
  if($str1){ 
  $fileName = trim($fileName,$str1); 
}
Copy after login
This is a very extreme example, and this processing is not very rigorous. If the name $fileName = a.b.c.d, without a suffix, it will be processed in the same way. Dropped:)



The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

php implementation of converting time difference into string

Use php to implement addition and subtraction verification code


The above is the detailed content of About the method of subtracting strings in disguised form in PHP. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template