|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
Here is two main functions. First function will call second function and second function will highlight the code and return the result to first function.
|
<?php
// function to call
function highlight_code($txt){
$hasil = preg_replace_callback('{\[code\]((.|\n)+?)\[/code\]}i',"replace_code", $txt);
return $hasil;
}
// main function
function replace_code($ketemu){
$hasil = trim($ketemu[1], "\n ");
return highlight_string($hasil, true);
}
?> | |
Here is a sample of usage:
| <?php
// sample of usage:
$string = "It's how to call PHP info: [code]<?php phpinfo(); ?>[ /code]";
echo highlight_code($string);
?> | | |
|
| A few functions to create random passwords. Categories : PHP, Security, Strings | | | A function that parses a string and replaces
http://whatever with a link, and email addresses with a
mailto link. This function was designed for the
motd package. But will work freely on its own.
Categories : PHP, Strings | | | Functions that will format a date in either long or short format from a string. Categories : Date Time, Strings, PHP | | | Remove URL Parameter Substr Strstr Categories : PHP, URLs, Strings | | | Mimic ASP's GetString function with PHP Categories : PHP, Databases, MySQL, Strings | | | Using PHP to show text in random colors Categories : PHP, Beginner Guides, Strings | | | Allows you to parse a deliniated string and put the individual fields in a SELECT option in a form Categories : HTML, PHP, Strings | | | columned txt file to array()? Categories : Arrays, Strings, Regexps, PHP | | | Working with files - putting file contents to a string / var Categories : PHP, Filesystem, Variables, Strings | | | Pull deliniated text strings into a "SELECT" statement in a form. Categories : HTML and PHP, PHP, Strings | | | Using data from a string. Categories : PHP, Strings, CURL | | | Calculator for Baroque Violin strings Categories : Math., PHP, Strings | | | Simple Email address validation Categories : Email, PHP, Strings | | | Look for the *position* of the first occurence of string2
in string1, beginning at position start.
Categories : Complete Programs, PHP, Strings | | | Compare two texts and display a block of text with the differences between them. Categories : PHP, PHP Classes, Filesystem, Strings, Arrays | |
| | | | Jason Hopkins wrote :1821
What exactly is the point in this? It would be faster and
simpler to strip the tags, highlight the code, and then
replace the tags. 'preg_replace_callback' makes this
script a little to slow to be useful. (On a side
note...I've learned that it's a little easier/faster to
scan through each letter looking for the tags and then
doing what needs to be done withing the tags.
| |
|
|