/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Modifying a file and saving it.

I am making templates for my site for users to be able to use. What would the best way to insert information into the templates?

Find line: [B]This is some text the user will see[/B]

[CODE]<div class=”navigation”>
<a class=”nav_link” href=”user_index.php?uname=admin”>Home</a>
<a class=”nav_link” href=”page2.php?uname=admin”>Email</a>
<a class=”nav_link” href=”page3.php?uname=admin”>Images</a>
<a class=”nav_link” href=”page4.php?uname=admin”>Resume</a>
</div>
<div class=”navigation_hor_bar”>&nbsp;</div>
<div class=”body_text”>
This is some text the user will see
</div>[/CODE]

Right now that code is saved in a text file, and the line that I previously showed needs to be changed depending on what the user enters into a text area, then the whole file needs to be saved into the database. How would I go about this?

Would using a different file name be easier to do this?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisNov 11.2006 — For your "This is some text the user will see" you should use a unique keyword as a placeholder in your template. For example:

##BODYTEXT##

Then, you can read in that template using the [B]file_get_contents()[/B] function. Next, replace the keyword(s) in the template:
[code=php]
$template = preg_replace('/##BODYTEXT##/', $usertext, $template);[/code]

Lastly, you should save this as a new file -- so that your original template is preserved for use by other users.
Copy linkTweet thisAlerts:
@The_Little_GuyauthorNov 12.2006 — OK thanks Ill try it, I'm just not going to be making a new file that is probably the only thing that I won't be doing... the file contents will be saved into the database.

Now if someone wants to modify the current text that they entered before... How would I get the text that they entered previously, then save the modified version back to the database?
Copy linkTweet thisAlerts:
@konithomimoNov 12.2006 — Instead of resaving the file simply have one file, and then for each user have a field/table that holds there modified values. If they do not have any then it will be the basic template, but if they do then those changes can be applied as so_is_this suggested.
Copy linkTweet thisAlerts:
@so_is_thisNov 12.2006 — ...the file contents will be saved into the database.

Now if someone wants to modify the current text that they entered before... How would I get the text that they entered previously, then save the modified version back to the database?[/QUOTE]

Yep, just save the users customization text selection(s) in the database, then perform the template merge on the fly as the user's page is requested.
Copy linkTweet thisAlerts:
@bokehNov 12.2006 — [code=php]$template = preg_replace('/##BODYTEXT##/', $usertext, $template);[/code][/QUOTE]No need for a regex to find a literal. In my opinion [I]str_replace()[/I] would be preferable in this context.
Copy linkTweet thisAlerts:
@so_is_thisNov 12.2006 — I agree. My use of RegExp is a hold-over-type habit from JavaScript -- which doesn't (didn't?) have a string replace method that doesn't use RegExp. ?
Copy linkTweet thisAlerts:
@The_Little_GuyauthorNov 13.2006 — Yep, just save the users customization text selection(s) in the database, then perform the template merge on the fly as the user's page is requested.[/QUOTE]
That is what I did thanks for the idea. It works.
Copy linkTweet thisAlerts:
@so_is_thisNov 13.2006 — It should -- that is what a CMS system is. ?

Salud!
×

Success!

Help @The_Little_Guy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...