Apr
30
2009
0

PHP’s function Code Highlighting

Just recently i discovered something very usefull. It could be very helpfull in any website or forum regarding programming.

There is a function in PHP called Code Highlighting. This would result in a very easy way of displaying php code onto a website. Just let me give an example.

<?php
highlight_string('<?php echo "test"; ?>');
?>

This outputted this in the displayed HTML:

<span style=”color: rgb(0, 0, 187);”>&lt;?php&nbsp;</span><span style=”color: rgb(0, 119, 0);”>echo&nbsp;</span><span style=”color: rgb(221, 0, 0);”>”test”</span><span style=”color: rgb(0, 119, 0);”>;&nbsp;</span><span style=”color: rgb(0, 0, 187);”>?&gt;</span>
</span>

Which looks just like this:
<?php echo “test”?>

As you can see, this can be very helpful.

Of course you need to be careful with this function as soon as you use it in “public”. You need to make sure you escape every quotes in the string with addslashes. This will prevent anything from happening.
Of course i can’t guarantee 100% protection. That’s pretty tricky. Good luck!
PS: http://nl2.php.net/manual/en/function.highlight-file.php

Written by Rene Pot in: Sugestions, general | Tags: , , , , , ,
Apr
27
2009
0

PHP 5 Recipes: A Problem-Solution Approach

Recently I bought this PHP book, and i must say, it’s a good one! There is more than just some examples. They show you how to fix a problem the best way! It is really worth buying.

Just want to recommend a good book!

PHP 5 Recipes: A Problem-Solution Approach


Sep
26
2008
1

Work with function ezSQL

Since a couple of weeks i work with ezSQL. And i came to the conclusion this function is much more usefull than the normal mySQL tags. It is very easy in ezSQL to get 1 row, or multiple. And the output is in a simple array!

I’ll just show you with some code below.

<?php
 
// First connect to database
 
$db = new ezSQL_mysql(DB_USER,DB_PASSWORD,DB_NAME,DB_HOST); 
 
// Get items from database
 
$playlists = $db->get_results("SELECT * FROM playlist ORDER BY id DESC");
 
// And now just print it.
 
foreach ($playlists as $item) {
    echo('Name is: '. $item->name .'.');
}
 
?>

As you can see it works very easy with a database. Besides get_results ezSQL has some other functions.

<?php
 
$row = $db->get_row(" SELECT * FROM playlist WHERE id=5"); // Just get 1 row
 
$var = $db->get_var(" SELECT name FROM playlist WHERE id=5"); // Just get 1 variable
 
?>

Ofcourse there are many other features in ezSQL. I would say try it for yourself! Go get it at http://www.woyano.com/jv/ezsql

Thanks for reading this post! I hope it has been of good use.

Examples and documentation can be found Here

Written by Rene Pot in: Sugestions | Tags: , , ,

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes