scvinodkumar Posted July 16, 2009 Share Posted July 16, 2009 hi, I have content like this "success adding the records in the river table by scvinodkumar today at 6.36 pm by scvinodkumar [[Category:Test]]" Now, i want to remove the "[[Category:Test]]" from the above content. Please tell me how to remove this? Link to comment https://forums.phpfreaks.com/topic/166155-removing-the-text-inside-brackets/ Share on other sites More sharing options...
dpacmittal Posted July 16, 2009 Share Posted July 16, 2009 Try this: $text = "success adding the records in the river table by scvinodkumar today at 6.36 pm by scvinodkumar [[Category:Test]]"; preg_match("!^(\[\[.*?!\]\])$!s" , $text , $matches); echo $matches[1]; Link to comment https://forums.phpfreaks.com/topic/166155-removing-the-text-inside-brackets/#findComment-876396 Share on other sites More sharing options...
nrg_alpha Posted July 16, 2009 Share Posted July 16, 2009 dpacmittal, the OP wants to remove, not match. Try this: Example: $str = '"success adding the records in the river table by scvinodkumar today at 6.36 pm by scvinodkumar [[Category:Test]]"'; $str = preg_replace('#\[{2}[^]]+\]{2}#', '', $str); echo $str; Link to comment https://forums.phpfreaks.com/topic/166155-removing-the-text-inside-brackets/#findComment-876464 Share on other sites More sharing options...
ghostdog74 Posted July 18, 2009 Share Posted July 18, 2009 no need regex. simple split will do $string = "success adding the records in the river table by scvinodkumar today at 6.36 pm by scvinodkumar [[Category:Test]]"; $s = explode("[[Category:Test]]",$string); print $s[0]; Link to comment https://forums.phpfreaks.com/topic/166155-removing-the-text-inside-brackets/#findComment-877548 Share on other sites More sharing options...
nrg_alpha Posted July 18, 2009 Share Posted July 18, 2009 Hmm.. I used regex under the assumption that [[Category:Test]] would be dynamic (in other words, the format would be [[ ..something : something.. ]], but I could be wrong. Link to comment https://forums.phpfreaks.com/topic/166155-removing-the-text-inside-brackets/#findComment-877561 Share on other sites More sharing options...
dpacmittal Posted July 19, 2009 Share Posted July 19, 2009 Since it is a category name, I assume it IS dynamic and nrg_alpha is right. Link to comment https://forums.phpfreaks.com/topic/166155-removing-the-text-inside-brackets/#findComment-877818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.