May I ask if PHP uses a regular expression? The following two situations may occur in a project,
First:
... SADFA:
123
SLDKJLSKDFJ .........
Second:
... SADFA:
0
SLDKJLSKDFJ .........
Excuse me, can I use a regular expression to express it?
What I think:
Preg_match ("/SADFA :.*? (\ D +)/is ", $ text, $ reg );
In this way, we get the value 0 in javascript: void (0,
Change it to the following:
Preg_match ("/SADFA :.*? ([1-9] \ d *)/is ", $ text, $ reg );
I can get the number of the red part, but if the red part is 0, I can't help it. please help...
Reply to discussion (solution)
Use preg_match_all ()
Use preg_match_all ()
In the first case, I need a second number,
In the second case, I want to take the first number,
I want to use a regular expression. I don't know how to write it.
$ S = <TXT first :........ SADFA: 123SLDKJLSKDFJ ......... the second type :........ SADFA: 0SLDKJLSKDFJ ......... TXT; preg_match_all ('/SADFA :. + [> \ s] (\ d +) \ B/sU ', $ s, $ r); print_r ($ r );
Array
(
[0] => Array
(
[0] => SADFA:
123
[1] => SADFA:
0
)
[1] => Array
(
[0] = & gt; 123
[1] => 0
)
)
Thanks to the two above, they can solve the problem from different ideas,
Due to the huge data volume, I don't know if strip_tags will affect the efficiency or try again. thanks to baoxiaohua.
I personally prefer the xuzuning method, which is exactly what I want to find. I have never thought of it. thank you very much.
My final/SADFA :.*? [> \ S] (\ d +)/is, saving non-greedy match. I don't know if there will be any problems ..