strago Posted November 16, 2012 Share Posted November 16, 2012 (edited) $source = str_replace("", "", $db_source).')'; $source = "(" . $source; $source = str_replace('()', '', $source); What can I add to this so that if there's a : in it, it all get's competly removed. It would be in these formats... (Text 7:9) (Text 1:26-27) (Text 1:12, 25) (Text 6:5-6, 9) Edited November 16, 2012 by strago Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 16, 2012 Share Posted November 16, 2012 (edited) Why don't you show the input and the desired output. You code doesn't make sense. The first line replaces a null string with a null string and adds a right paren to the end of the string. The second line adds a left paren to the beginning of the string. The third line replaces a left and right paren with an empty string. I assume this last step is to remove the value entirely if the originating input was empty. You could have replaces those three lines with $source = (!empty($db_source)) ? "({$db_source})" : ''; But, your request is not even clear. What do you mean by "it all get's competly [sic] removed"? If you mean the value for one $db_source then you could simply check if there's a colon $source = (!empty($db_source) && strpos($db_source, ':') === false) ? "({$db_source})" : ''; Edited November 16, 2012 by Psycho Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 Depending on your response to psycho's questions, regular expressions may be an answer. Quote Link to comment Share on other sites More sharing options...
strago Posted November 17, 2012 Author Share Posted November 17, 2012 Thanks. That did exactly what I was trying to do, completly remove the $db_source value if it had a : in it. Quote Link to comment 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.