Php uses regular expressions to process values that are not required in strings. Today, when collecting images from the Momo website, the resolution of the images will be changed to 320*480, and the original images contain pixel information. For example, the clear Hut (320 today, when collecting images on Mo's Web site, because I will eventually change the image resolution to 320*480, the original image contains information about pixels.
For example, clear Cottage (320*480) wallpaper
So what should I do if I want to leave the "clear cottage wallpaper?
First, we should immediately think that we should first find the string and remove it.
Well, first of all, I thought so too. I defined an array and saved several strings, such as (320*480) and (480*640). but later I found that, if there are other types of stream (320*234), it is not impossible for me to list them all, but it is just a matter of time. But we don't want to do this. it's boring. It is estimated that half a day has passed, and it is quite uncomfortable.
So what should we do?
First, observe multiple pieces of data. we found that there should be "*", which must be known. Otherwise, the values that do not have to be included will increase the workload of the computer.
Here comes:
[Php]
If (strchr ($ title ,"*"))
{
Used to determine whether a string contains "*";
If so, there must be something we want to remove. what should we do next? find the string to be removed and replace it with NULL? Obviously, you cannot find it in the way above.
I used the string cutting method:
[Php]
$ Arr = split ('([\ (] *) [0-9] + \ * [0-9] + ([\)] *)', $ title ); // * be sure to escape
$ Title = $ arr [0]. $ arr [1];
([\ (] *) [0-9] + X [0-9] + ([\)] *) is a regular expression,
([\ (] *) Indicates that there may be (
[0-9] + indicates that at least one number from 0 to 9 exists.
[Php]
"*"
So the above (320*480) is easy to find.
Here is the test program.
[Php]
$ Title = "clear Hut (320*480) wallpaper ";
If (strchr ($ title ,"*"))
{
$ Arr = split ('([\ (] *) [0-9] + \ * [0-9] + ([\)] *)', $ title ); // * be sure to escape
$ Title = $ arr [0]. $ arr [1];
Echo $ title;
}
?>
Author: wolinxuebinBytes. For example: clear Hut (320...