How to identify a 'delimiter' in a string with php?

0

In my problem a delimiter is two strings that 'encompass' a part of another string in a given order. For example: '(' and '}' are a string delimiter: 'aqui (tem} um delimitador' .

My problem is like identifying a delimiter in one string to replace it with another.

    
asked by anonymous 19.03.2016 / 22:53

2 answers

3

I believe this function can help you. If you are unsure of the syntax and other options see link

// Fornece: aqui tem} um delimitador
$bodytag = str_replace( "(", "", "aqui (tem} um delimitador");

In this simple example I just changed the character '(' by '', I did this to remove the delimiter.)

If you want to replace with something put in parameter 2. You can repeat the function to take as many as you need or to make an array with the unwanted characters.

    
20.03.2016 / 02:51
0
$string = 'ola {cabra} aaa';
$rules = str_replace(array("{","}"), array('[',']'), $string);
print($rules);
//retorna: ola [cabra] aaa
    
19.03.2016 / 23:19