I’m using file_get_contents(‘mysourcefile.html’) to load the contents of mysourcefile.html into mysql db.
I have two things that I want to do to the contents of mysourcefile.html before I insert it into the db.
First…
I’d like to do a find/replace on specific string matches contained in mysourcefile.
For example: the tags that a user may place in their source input files would look something like this:
Welcome to [site-name], located at
[site-url] contact us at [site-email]
if you need help.
And I’d like to do a simple string match replacement on these values as they appear in the source file before they are written to the db. The replacement text would come from the wordpress database setup fields. For example, get_option(‘admin_email’) and get_option(‘home’)
Secondly…
I’d also like to allow the user to specify, via a special bracket, a string of words in which to use in order to randomize the content each time its imported, using the same input source file.
For example, in the above sentence, it might be encoded in the source file like so:
I’d also [%like|prefer|want%] to
[%allow|permit%]the user to
[%specify|declare|select%] via a
[%special|unique|predefined%] bracket,
a string of [%words|characters|text%]
in which to use in order to randomize
the content from site to site, using
the same input source file.
So I want to parse that content string and do a simple random replacement of each set element to pick one word out of the collection and use that word for the insert.
Its basically a crude content replacement/spinner and I’m looking for some direction and methods which I could use to do it.
For the first part:
The second part might be a little trickier. But the process is:
So .. you’ll need someone who knows Regex.