Jump to content
MakeWebGames

Recommended Posts

Posted

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);

Posted

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?

Posted

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

Posted

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[!]).

Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...