Código PHP:
if (isset($_POST['rtf'])){
// Lee la plantilla
$plantilla = file_get_contents('prueba.rtf');
// Agregamos los escapes necesarios
$patron = '/\\\\\'(.)(.)/i';
$reemplazo = '\'$1$2';
$plantilla = preg_replace($patron,$reemplazo,$plantilla);
$plantilla = addslashes($plantilla);
$plantilla = str_replace('\r','\\r',$plantilla);
$plantilla = str_replace('\t','\\t',$plantilla);
// Datos de la plantilla
$nombre = $_POST["nombre"];
$apellido = $_POST["apellido"];
$fecha = date("d-m-Y", time());
// Procesa la plantilla
eval( '$rtf = <<<EOF_RTF
' . $plantilla . '
EOF_RTF;
' );
// Guarda el RTF generado, el nombre del RTF en este caso sera el apellido-nombre.fechaactual.rtf
file_put_contents("$apellido-$nombre-$fecha.rtf",$rtf);
echo "<a href=\"$apellido-$nombre-$fecha.rtf\">descargar</a>";
}
Código HTML:
<form action="index.php" method="post"> <input name="nombre" type="text" />Nombre<br /> <input name="apellido" type="text" />Apellidos<br /> <input name="rtf" type="submit" value="Modificar archivo" /> </form>
Código:
Parse error: syntax error, unexpected $end in /home/XXX/index.php(30) : eval()'d code on line 18