I want to use a WordPress style shortcode in my own CMS. For example, with Embedded Tweets, I can say:
[tweet 'TWEET URL']
and the tweet will be embedded with the standard format as supplied by Twitter. Similarly with YouTube videos:
[youtube 'YOUTUBE VIDEO']
will embed the YouTube video player. How would I do that with PHP and MySQL? I am not looking for a ‘generic’ system; manually adding shortcodes would work just fine with me, as long as I know what I am doing.
WordPress has a fairly elaborate scheme for processing post/page content in the dbms and depositing it in the output stream. Part of that involves scanning the text for registered shortcodes and replacing them with the appropriate URLs or other text.
The WordPress Codex explains how to write a plugin to implement a shortcode. There are plenty of examples to look at.
http://codex.wordpress.org/Shortcode_API
But if you’re going to immplement this in your own CMS you need to build your own scheme for processing content, and tie processing into it.
If you have the ability to install custom extensions from PECL, i would suggest the BBCode Extension for PHP.
Example from the official documentation:
Would return:
If you can’t install the extension, look at this PHP Library which you can include in user-land code.