String Replace In An Array
Posted: Mon Oct 25, 2004 6:48 am
Hey ALL - New member first time poster here , 
I have a PHP script that I would like to modify, unfortunatly, my stong point in servers, hardware, *nix, etc.. not programming. I do have a basic understanding and can usually make small changes and customizations.
I have a script (see code below) that created a 1 page site from a templatate taht is on the server. It take the information the person enters into a form and them proccesses it - put the data from the form into the HTML template in between "comment tags" for each of the fields.
What I Want To Do:
I want to be able able to do some kind of "string replce" on the array BEFORE it processes the HTML page.
I would the user to be able to put a few basic HTML commands into the form, problem is my users do not know them, So instead if a user could put "NEWLINE" in the form, the script would reaplce that with "<BR />" , hopefully this makes sence.
I only want a few things, like a new line, to be able to bold some text, and maybe Ittalics.
Any help would very nice
Also, if I am totally wrong on the string replace thing here and there is another way of doing it, please let me know.
AJ
I have a PHP script that I would like to modify, unfortunatly, my stong point in servers, hardware, *nix, etc.. not programming. I do have a basic understanding and can usually make small changes and customizations.
I have a script (see code below) that created a 1 page site from a templatate taht is on the server. It take the information the person enters into a form and them proccesses it - put the data from the form into the HTML template in between "comment tags" for each of the fields.
What I Want To Do:
I want to be able able to do some kind of "string replce" on the array BEFORE it processes the HTML page.
I would the user to be able to put a few basic HTML commands into the form, problem is my users do not know them, So instead if a user could put "NEWLINE" in the form, the script would reaplce that with "<BR />" , hopefully this makes sence.
I only want a few things, like a new line, to be able to bold some text, and maybe Ittalics.
Any help would very nice
Code: Select all
function make_page($sTemplatePath, $pageBase, $sNewFileName, $fieldArray){
// $sTemplatePath: the relative path to the template that we parse
// $pageBase: the relative path to the base dir.
// $sNewFileName: the name for the created file after template parsing
global $Member_ID;
while(list($key,$val) = each($fieldArray)) {
$fieldArrayї$key] = stripslashes($val);
}
reset($fieldArray);
if(!isset($fieldArrayї'img1'])){
$fieldArrayї'form_email'] = "<input type="hidden" name="recipient" value="{$fieldArrayї'owner_email']}">";
$fieldArrayї'form_id'] = "<input type="hidden" name="Member_ID" value="$Member_ID">";
}
// Get The Template HTML & Combine Into A String
$template = file($sTemplatePath);
$template = implode('', $template);
// Insert Data Between The Comment Tags
while(list($sFieldName, $value) = each($fieldArray)){
$sReplaceString = "<!--field $sFieldName-->.*<!--end $sFieldName-->";
$sReplaceWith = "<!--field $sFieldName-->$value<!--end $sFieldName-->";
$template = ereg_replace($sReplaceString, $sReplaceWith, $template);
}
//If The Folder Doesnt Already Exist, Create It.
if (!(@opendir("$pageBase/$Member_ID"))){
mkdir("$pageBase/$Member_ID", 0777);
chmod("$pageBase/$Member_ID", 0777);
}
if (!(@opendir("$pageBase/$Member_ID/{$fieldArrayї'address']}"))){
mkdir("$pageBase/$Member_ID/{$fieldArrayї'address']}", 0777);
chmod("$pageBase/$Member_ID/{$fieldArrayї'address']}", 0777);
}
$file = fopen("$pageBase/$Member_ID/{$fieldArrayї'address']}/$sNewFileName", 'w');
fputs($file, $template);
fclose($file);
chmod("$pageBase/$Member_ID/{$fieldArrayї'address']}/$sNewFileName", 0777);
}AJ