Thread: Tech Whats this called?
View Single Post
Old 01-24-2022, 08:29 PM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
You just do a str_replace in the page. https://www.php.net/manual/en/function.str-replace.php

Pull the text for your page into a string.

Pull your data from the database.

Replace any tags in the data string with the appropriate data.

For example:

Database of people and in there are their first name, last names and age.

We are going to send out multiple letters to various people.

So, here is the text that we are going to use:

"Dear [first_name] [last_name],
We see that you are [age] years old, [first_name]. "

We have that stored in a variable called datastring


Then we pull the data:

Select firstname, lastname, age from data_table

Then we loop through the returned data

while we have data:

Letter=str_replace(array($row['firstname'],$row['lastname'],$row['age']),array('[first_name]','[last_name]','[age]'), datastring);

Each occurrence of [first_name] will be replaced by the data in $row['firstname'], etc.

send the letter

then next letter

That make sense?

You might be able to find other stuff by searching on replacing template tags, things like that. The text is the template and the tags are the fields in the template that designate what to replace.

There are several template systems out there that are pre-canned also.
.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote