jeudi 18 octobre 2018

PHP - Replace everything between String including content

I want to iterate over a string which looks like this.

Booo ahh [Hello] and what is [Baby] at your [Mouse]

My target is to replace every [@@@] with another string, which is not static, but can handle the content between the brackets.

Should be something like

function replace_string($text) {
 ...
 //Maybe some kind of loop for all brackets
 {
  $content = ... //For example Hello, Baby, Mouse => @@@
  $replacement = "I'm a " . $content . "!";
  ...
 }
 return $replacedString;
}

I don't think it can work like in my "suggestion", but I hope I could show what I want to do and somebody can help me.




Aucun commentaire:

Enregistrer un commentaire