What should I do if I only want to keep the first regular expression string in PHP? PHP
For example, there are many asd strings, several consecutive strings, and only one string,
But I want to keep only the first asd and delete all the asd behind it. what should I do?
(Based on other characters not affected)
Ssssssssgsdfasdasdasdjlkjhkjhalkasdasdjsdkajshdasdaklsjdasdhkjashgdaklsh
Expected results:
Ssssssssgsdfasdjlkjhkjhalkjsdkajshdaklsjdhkjashgdaklsh
Please give me some tips
Reply to discussion (solution)
$ S = 'handler'; $ t = 'handler'; $ s = preg_replace_callback ('/asd/', function ($ r) {static $ n = 0; return! $ N ++? $ R [0]: '';}, $ s); var_dump ($ s = $ t );
Bool (true)
I have no time in a day. thanks very much to the moderator. Yes, this is the effect. it turns out that there is something as useful as preg_replace_callback. does preg_replace not have this function? Moderator