for my website, I want a simple BB code system. Nothing special--just hyperlinks and images will be fine for now.
I'm not good with RegExp. Period. But if someone could show me an example, I may be able to grasp it to clone it into different tags.
Your help is very appreciated!
The user asked for something simple, so I gave him something simple.
Where
/\[link=(.*?)\](.*?)\[\/link\]/
is the regex,<a href="$1">$2</a>
is the format,$input
is the input/data, and$replacement
is the return.I have to imagine this exists out there for free somewhere, but here's how I'd do it.
Output:
For each
$pat
pattern element you add, you need to add a$rep
element. The$DIRTY
array is just a list of test cases and can be any length you think is sufficient.The important parts here, and the parts that you would use are the
$pat
and$rep
arrays and thepreg_replace()
function.