Page 1 of 1

Import files with custom templates

Posted: Tue Mar 21, 2006 7:47 am
by sietjp
Hello,

I would like to implement an importation process in a website that can manage almost any kind of text file with a system of custom templates.

I would like your opinion about the methid I should use.

My first idea was to use the paterns with the function eval() of php.

For example

I have a text file like this

Code: Select all

// Config file
toto_var="toto";
titi_var="\"titi\"";
// End of file
I would like to import in my database the list of couple (var,value)

So I wouls like the user can enter 3 string :

1st string, import template : for example
^(.+)="(.+)"$
2nd string, var result :
//1
2nd string, value result :
@myfunction(//2)
This is an example. The 1st, 2nd and 3rd strings can be changed by the visitor of my website through a form.

If we assume @myfunction is in fact a function that delete "\" in its parameter string, the result of my importation process in database will be :

Code: Select all

variable   |   value

toto_var   |   toto
titi_var     |   "titi"
I would like to use the php patterns as developping my own syntac will be a hard and long work. And I had plan to use eval() but is this the good method? Can't it be a security problem using eval()?


My last question is : Do you kow exemples of such a functionnality of which we can see the source code?

Thansk a ot for your help!