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Ā 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; ?> 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
Archived
This topic is now archived and is closed to further replies.