What are best practices for integrating geshi with MySQL to select and highlight code between specific tags, such as [code]?
To integrate GeSHi with MySQL to select and highlight code between specific tags like [code], you can use regular expressions to extract the code within the tags and then apply GeSHi for syntax highlighting. One approach is to fetch the code from MySQL, use a regular expression to extract the code between [code] tags, and then pass that code to GeSHi for highlighting.
// Fetch the code from MySQL
$code = "SELECT code FROM your_table WHERE id = 1";
// Extract code between [code] tags using regular expression
preg_match('/\[code\](.*?)\[\/code\]/s', $code, $matches);
$code_to_highlight = $matches[1];
// Initialize GeSHi
require_once('geshi/geshi.php');
$geshi = new GeSHi($code_to_highlight, 'language');
// Display highlighted code
echo $geshi->parse_code();
Related Questions
- Are there best practices or alternative methods to access values set by JavaScript in PHP when parsing web content?
- How can developers ensure the security of user passwords when using MD5 hashing in PHP applications?
- Are there any potential pitfalls to be aware of when using Spline Interpolation in PHP for curve generation?