I am working on a feature where I need to replace a string of text, extract a parameter from it, and call a function based on the associated string. Kind of like a shortcode system.
I want to allow the user add text in the body of a page like {content=whatever}
then I want to take that shortcode, and replace it with a function call to whatever()
I want it basically to be scalable so that my code will automatically call the function named exactly as the string
So far, I have it working in a non-scalable way, so i'd need to always add if statements whenever a new scenario arises.
if (str_replace($content, '{content=getStudents}')) {
return getStudents();
}
So as you can see, if i want different types of content, like grades, exams etc.. I'd need to keep adding to that if statement.
Any help is appreciated. I am pretty poor with regular expressions, I have been on https://regexr.com/ and I can't get anywhere close to what I need.