G'day,
I am reading the contents of a file and placing that text into a form. The user can then update the file by editing the text in the form and submitting it.
The problem I am having is how to separate the html (and PHP) from the text itself.
Say, for example, the file contained the following:
<b>Greatest Sports Heroes</b>
I would like to put the text ("Greatest Sports Heroes") into the form
and leave out the html tags. However, I need a way to put those html tags
back into the appropriate places in the file when the user submits.
//I am doing this:
$text = fread($fp, filesize($file));
//but this gives me the text and the html tags
//I have also toyed exploding the contents into an array, like this:
First, I add a | at the end of what will become the array elements,
<b>|
Greatest Sports Heroes|
</b>|
Then, I explode the variable by the |'s
$text = fread($fp, filesize($file));
$pieces = explode("||",$text);
//Now I have
$pieces[0] = "<b>"l
$pieces[1] = "Greatest Sports Heroes|";
$pieces[2] = "</b>|";
So, I can now print "Greatest Sports Heroes" into my form value, but, then I have the problem of not wanting to display the |'s, so when I print the page, I have to str_replace the |'s.
Any ideas on a better way to do this?
I don't want to go to a database