POG1 Posted August 10, 2009 Posted August 10, 2009 Ok i got a text file and it has variables stored like so; [!]page_title[!] How could i use it to convert into a variable (so {$page_title}) using a regex string? I have thought about something like.. preg_match("\[\!\]([a-zA-Z0-0])+\[\!\]","{\$$1}",$file); Quote
Floydian Posted August 10, 2009 Posted August 10, 2009 Re: Replace Are you able to control how the data is stored or does it have to be stored in the format stated? Quote
POG1 Posted August 10, 2009 Author Posted August 10, 2009 Re: Replace The data can be stored in any way and it can also be stored in any format. Quote
Haunted Dawg Posted August 10, 2009 Posted August 10, 2009 Re: Replace Why use preg_match or even preg_replace for simple string's? str_replace('[!]page_title[!]', $page_title, $html); I would take it you would insert that into a function which is being run by ob_start? Quote
POG1 Posted August 10, 2009 Author Posted August 10, 2009 Re: Replace well what i was trying to do is load the header of a page in from a text file. The text file will have a load of variables in it and I thought the best and easiest method was to just preg replace using a rgular expression Quote
Haunted Dawg Posted August 10, 2009 Posted August 10, 2009 Re: Replace If that's the case.. $output = preg_replace('~\[!\](.*)\[!\]~is',$.'$1', file_get_contents('headerfile')); echo $output; you could try. Quote
POG1 Posted August 10, 2009 Author Posted August 10, 2009 Re: Replace hmm that didnt work. At the minute I have a working function but I want it so it does them all without having to manually add them in and do str replace. Here is what i have working: echo str_replace($from, $to, file_get_contents(DIR_TEMPLATES.'/'.$this->t.'/header.html','r')); the from and to arer arrays of the values (so like [!]GAME_TITLE[!] and [!]USERNAME[!]). Quote
Floydian Posted August 10, 2009 Posted August 10, 2009 Re: Replace Hey POG1, you didn't answer my question, so I might be off base here. Here's my suggestion: Store your data in JSON format. Bring it into your script with file_get_contents and json_decode (using the second parameter of true so that you force it to be an array). Then call export(). You should see all the keys in the array become local variables. And all of this should be super fast. Hope that helps. Quote
POG1 Posted August 10, 2009 Author Posted August 10, 2009 Re: Replace Thanks for the idea, i'm a n00b when it comes to JSON so i won't even try. In the mean time i have a better solution. Ii made the text file so it has php and just used this code echo eval(file_get_contents(DIR_TEMPLATES.'/'.$this->t.'/header.html','r')); I dont know if it is the best way but it seems like it is the easiest way. Quote
Haunted Dawg Posted August 11, 2009 Posted August 11, 2009 Re: Replace Just be careful what user's can add to the template file's ;) Quote
POG1 Posted August 11, 2009 Author Posted August 11, 2009 Re: Replace users wont be able to add to it, they would be stored above public_html so it also cannot be viewed. Quote
POG1 Posted August 11, 2009 Author Posted August 11, 2009 Re: Replace lol "POG1 and 16 Guests are viewing this topic. " Quote
CrazyT Posted August 11, 2009 Posted August 11, 2009 Re: Replace lol "POG1 and 16 Guests are viewing this topic. " LOL!!! 1 guests viewing now. XD Quote
Floydian Posted August 11, 2009 Posted August 11, 2009 Re: Replace Here you go POG1: http://criminalexistence.com/ceforums/i ... ic=29999.0 Hope that helps. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.