mojobadshah Posted May 6, 2020 Share Posted May 6, 2020 (edited) I would like to be able to use a succession of php preg_match() and preg_replace() functions in one script without having to produce clutter in this match and replace php coding script and without its results showing arrayed forms. The following is a RegExp formula that I'm comfortable with that involves only a replace function. I'm curious what the best way would be to scoot a RegExp match function into a script like this one that is consistent with the same $current .= preg_replace('/a/', 'b', $current); php code that I've shown here et. al. that can be written out on one string. I've seen some php implode() functions, but my concern is that an additional function as such along with preg_mach() functions will cause a lot of deviation in a list of regular regex match and replace functions. What can I do to keep both php match and replace RegExp functions strings typed out in linear concession for the sake of keeping things organized when strictly relating to regex functions and working with them within php and working something like an implode() function into my php script so that match and replace functions can produced organized results outside of having to make use of arrays? <?php $file = 'sample.txt'; $current = file_get_contents($file); $current .= preg_replace('/a/', 'b', $current); file_put_contents($file, $current); ?> Edited May 6, 2020 by mojobadshah Quote Link to comment https://forums.phpfreaks.com/topic/310713-prevent-arrays-with-preg_match-function/ Share on other sites More sharing options...
requinix Posted May 6, 2020 Share Posted May 6, 2020 What? The code you posted will take sample.txt, read what's in it, add to that another copy of what's in it but with the regex run on it, then dump that all back to sample.txt. So if you run the code multiple times then the files goes like a -> ab -> abbb -> abbbbbbb -> abbbbbbbbbbbbbbb... Quote Link to comment https://forums.phpfreaks.com/topic/310713-prevent-arrays-with-preg_match-function/#findComment-1577615 Share on other sites More sharing options...
benanamen Posted May 6, 2020 Share Posted May 6, 2020 How about telling us what the real problem is that you are trying to solve with this code. Quote Link to comment https://forums.phpfreaks.com/topic/310713-prevent-arrays-with-preg_match-function/#findComment-1577616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.