Php makes good use of regular expressions to process the Value & nbsp, in the end, I will change the image resolution to 320*480, and the original image contains pixel information. & Nbsp; e. g.: clear cabin (320*480) Wallpaper & nbsp; in the end, php makes good use of regular expressions to process the values 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, 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:
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:
$ 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.
\ * There is "*", so the above (320*480) is very simple to find out. Here is the test program.
<Pre name = "code" class = "php"> <? Php $ title = "clearhome (320*480) wallpaper"; if (strchr ($ title ,"*")) {$ arr = split ('([\ (] *) [0-9] + \ * [0-9] + ([\)] *)', $ title); // * be sure to escape $ title = $ arr [0]. $ arr [1]; echo $ title ;}?>