Shijin TR
Shijin TR

Reputation: 7768

Replace string with a particular format

I have a string with the following format,

 some_string%value1:value2:value3:%some_anather_string%value4:value5:value6:%

I need to remove%value1:value2:value3:% and %value4:value5:value6:% from the string,i mean i need to remove any string with the format of starting with % ending with :% and values seperated with :

Is this possible?

I try with str_replace(),But it work only we know the values.

Upvotes: 3

Views: 146

Answers (1)

Use can use this simple regex

echo $str = preg_replace("~%(.*?):%~","", $str);

Demonstration

Upvotes: 4

Related Questions