WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Syntax Highlight - This is a PHP function to highlight PHP code in a string/text.
Categories : PHP, Strings
Yeni Setiawan
Date : Jul 19th 2008
Grade : 3 of 5 (graded 4 times)
Viewed : 3747
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Yeni Setiawan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
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);
?>



mysql_escape_string
Categories : PHP, MySQL, Databases, Strings
How to Get a character array from a string
Categories : PHP, Strings, Arrays
AddSlashes -- Quote string with slashes
Categories : PHP, PHP Functions, Strings
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Printer friendly pages from anywhere on a website.
Categories : PHP, Strings, Content Management
STR - a Perl-like string manipulator class - The str class provides 4 perl-like methods for manipulating strings and other scalar variables.
Categories : PHP, PHP Classes, Perl, Strings
Grab images from one or more URLs and save them to a specified local directory.
Categories : PHP, Filesystem, Strings, Arrays
explode() and SQL blobs
Categories : General SQL, Strings, PHP, Databases
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
Remove URL Parameter Substr Strstr
Categories : PHP, URLs, Strings
I need a trim function/regexp that will trim all " " from the ends of a string.
Categories : Regexps, PHP, Strings
textwrap fill-paragraph (justification)
Categories : Strings, PHP, Algorithms
Read a file with strings and create a new file with the first half of each string
Categories : PHP, Strings, Filesystem
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
 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.