Given the following:
$foo = “Yo [user Cobb] I heard you like dreams so I put a dream in yo dream in yo dream so you can dream while you dream while you dream.”
I’d like to do this:
$foo = bar($foo);
echo $foo;
And get something like this:
Yo Cobb I heard you like dreams so I put a dream in yo dream in yo dream so you can dream while you dream while you dream.
I’m unsure of how the bar function should work. I think this is doable with regular expressions but I personally find those hard to understand. Using the strpos function is another method but I wonder if there is a better solution.
Pseudocode is fine but actual code will be appreciated.
Edit:
These tags are not placeholders as the 2nd part is a variable value.
Edit:
All of the str_replace answers are incorrect as the tags contain variable content.
You could use preg_match_all to search the string for tags.
Now you can add more functionality by adding more cases to the switch.