This is how i would do it, however, I'm sure there is a better way so you might want to wait for more replies .
Anyway, your going to need 3 variables, the players Current Level, his current XP and the amount of XP required to gain the next level.
So obviously, when the player does something that grants XP, you just add whatever amount he gets to the current XP variable, then when the current XP variable is equal or greater than the required XP, increase the players level by 1 and reset the current XP back down to 0.
As for working out how much XP will be needed for each level without having a set pattern, i think you will need to work out a formula that will work for you. For example you might go:
Required XP = Current Level * 10 + 100
This would mean at level 4 you would need 140 XP to get level 5. Or at level 20 you would need 300.
You will obviously want to work out your own formula however.