Using PHP I need I will have an array of tag name => tag URL I need to somehow scan a text input (will be somewhat large, a blog post) and find all tag names in the text and replace them with the URL link. To complicate it though, if the tag name is inside <h1>, <h2>, or <code> and <pre> tags it will not do it. Possibly to simplify, I could say it has to be inside a <p> tag for the switch to take place.
I am not sure how to accomplish this, I know I will need regex but I am a bit lost at the moment, if anyone could help me some I would greatly appreciate it
so a PHP tag would be turned into <a href="link here">PHP</a>
You can use an XML parser like:
OR
The first approach will give you your tags in a searchable array. The second will give you a SimpleXMLElement object.
You can then use a simple foreach loop to iterate over the elements in your array or reference the variables in your SimpleXMLElement object. Have a look at the simplexml_load_string tutorial by W3C it’s very straight forward.