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)

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})" : '';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.