joshblue Posted June 26, 2008 Share Posted June 26, 2008 Hi, can someone please help me with this... I need to read a textfile. This is the contents of the textfile, for example: 100005HELLO WORLD L1 HELLO WORLD L2 100010THIS IS A SAMPLE L1 I need a script that would erase the numbers between 1 and the text (ex 100005HELLO WORLD) in every line only if the line has a string of L1 What do you think? ??? Quote Link to comment https://forums.phpfreaks.com/topic/112029-reading-erasing-string-in-a-particular-length/ Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 <?php $file = 'file.txt'; $contents = file_get_contents($file); echo preg_replace('/(\s+1)\d+(.+?L1)/','$1$2',$text); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112029-reading-erasing-string-in-a-particular-length/#findComment-575057 Share on other sites More sharing options...
sasa Posted June 26, 2008 Share Posted June 26, 2008 try <?php $text = ' 100005 HELLO WORLD L1 100000HELLO WORLD L2 100010THIS IS A SAMPLE L1'; echo preg_replace('/(?<=1)\d+(?=[a-z][^\n\r]*L1)/i','',$text); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112029-reading-erasing-string-in-a-particular-length/#findComment-575214 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.