Jump to content

Str_Replace - Remove Everything If It Has A : In It


strago

Recommended Posts

$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 by strago
Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.