SharkBait Posted June 15, 2011 Share Posted June 15, 2011 So how do I go about using preg_replace() to remove a portion of a string and ignoring the rest of it? String: [http://this.is.my.site.com/stuff/funn] this is cool! so that it only returns this is cool! I can't seem to get the regex pattern right Link to comment https://forums.phpfreaks.com/topic/239479-preg_replace-remove-things-between-but-ignore-rest/ Share on other sites More sharing options...
xyph Posted June 15, 2011 Share Posted June 15, 2011 More example data please. Link to comment https://forums.phpfreaks.com/topic/239479-preg_replace-remove-things-between-but-ignore-rest/#findComment-1230229 Share on other sites More sharing options...
SharkBait Posted June 15, 2011 Author Share Posted June 15, 2011 Anytime something shows up with [http://afdasdfsaf] I guess anytime a URL shows up within square braces, i want to remove the square braces and the contents within them I just want the the [http://afdasdfsaf] removed. Sorta like BBCode, but it isnt Link to comment https://forums.phpfreaks.com/topic/239479-preg_replace-remove-things-between-but-ignore-rest/#findComment-1230232 Share on other sites More sharing options...
JAY6390 Posted June 15, 2011 Share Posted June 15, 2011 $result = preg_replace('/\[[^]]*\]/', '', $subject); Link to comment https://forums.phpfreaks.com/topic/239479-preg_replace-remove-things-between-but-ignore-rest/#findComment-1230243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.