etrader Posted January 28, 2011 Share Posted January 28, 2011 I have a string taken from an array in a foreach with the following structure /MAINWORD/something/else ...... I want to catch only MAINWORD and remove everything elseĀ Quote Link to comment https://forums.phpfreaks.com/topic/225935-selecting-a-given-pattern-from-a-string-and-delete-everything-else/ Share on other sites More sharing options...
sasa Posted January 28, 2011 Share Posted January 28, 2011 <?php $test = '/MAINWORD/something/else ......'; $out = preg_replace('/\/([^\/]+)\/.*/is', '\1', $test); echo $out; ?> Quote Link to comment https://forums.phpfreaks.com/topic/225935-selecting-a-given-pattern-from-a-string-and-delete-everything-else/#findComment-1166510 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.