May
06
2009
0

Fresh Start

Because of my increase in experience in more languages than just PHP, i decided to make a suitable blog for that matter.

Therefor I decided to move any future posts to a new domain. And this will be www.renepot.com

I hope to see you all there!

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
24
2009
0

Mysql Full Text Search - Speed up those results

I just ran into the problem of a very big database, and a very slow search function..

At first i was a little confused, but soon i came to the conclusion of building a Full Text Search function.

The first problem on building this i encountered was the database coalition. You have to have a MyISAM database. So, that’s what i did.

  • Create a table:

CREATE TABLE news (content TEXT, title VARCHAR(250), id INT(11) NOT NULL auto_increment, PRIMARY KEY(id);

  • Add a fulltext index:

ALTER TABLE articles ADD FULLTEXT(content, title);

This FULLTEXT index makes an index on both content and title, so you can’t search just one of them.

  • Create a Query:
$query = "SELECT title,content,id, MATCH(title,content) AGAINST ('my search') AS score FROM news WHERE MATCH(title,content) AGAINST ('my search')";

Let me explain:

SELECT MATCH(title,content) AGAINST (’my search’) means you select the result of a MATCH. The result is a score. The higher the number, the better the result.

AGAINST (’my search’) searches in the selected fields in the MATCH (title,content) in my example. The search can be multiple words. The search searches for all words individually. You can also add a minus (-) and a plus (+) to a word, in order to change the priority. A minus tries searching a row without the word, a plus makes a word more imporant.

The reason the MATCH AGAINST is double in my query is just because i want to order my results (2nd time) and i want the score visible (1st time). I rename my MATCH AGAINST as Score, in order to get the score back out of the query. This would be something you could show on your page. Or do something with in your code.

If you want to limit the result by score, you have to add the following to the query:

HAVING score > 2 (you can change the number in anything you want, but this will filter the worst results)

Sep
25
2008
0

Introduce myself

First of all i would like to introduce myself to you.

I am Rene Pot, 20 years old and I already have approximately 4 years experience with PHP. 

I run my own company Topener and work for Syntraks / 1080dots. (www.1080dots.com) At 1080dots i’m developing the back-end for the play-list system. 

I also have some own projects running, so plenty of work to do!

Written by Rene Pot in: general | Tags: ,

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