Search
 
SCRIPT & CODE EXAMPLE
 

PHP

automatically create html page using php and mysql

<?php

// Session is started.
session_start();

// Name of the template file.
$template_file = 'couples-template.php';

// Root folder if working in subdirectory. Name is up to you ut must match with server's folder.
$base_path = '/couple/';

// Path to the directory where you store the "couples-template.php" file.
$template_path = '../template/';

// Path to the directory where php will store the auto-generated couple's pages.
$couples_path = '../couples/';

// Posted data.
$data['groom-name'] = str_replace(' ', '', $_POST['groom-name']);
$data['bride-name'] = str_replace(' ', '', $_POST['bride-name']);
// $data['groom-surname'] = $_POST['groom-surname'];
// $data['bride-surname'] = $_POST['bride-surname'];
$data['wedding-date'] = $_POST['wedding-date'];
$data['email'] = $_POST['email'];
$data['code'] = str_replace(array('/', '-', ' '), '', $_POST['wedding-date']).strtoupper(substr($data['groom-name'], 0, 1)).urlencode('&').strtoupper(substr($data['bride-name'], 0, 1));

// Data array (Should match with data above's order).
$placeholders = array('{groom-name}', '{bride-name}', '{wedding-date}', '{email}', '{code}');

// Get the couples-template.php as a string.
$template = file_get_contents($template_path.$template_file);

// Fills the template.
$new_file = str_replace($placeholders, $data, $template);

// Generates couple's URL and makes it frendly and lowercase.
$couples_url = str_replace(' ', '', strtolower($data['groom-name'].'-'.$data['bride-name'].'.php'));

// Save file into couples directory.
$fp = fopen($couples_path.$couples_url, 'w');
fwrite($fp, $new_file);
fclose($fp);

// Set the variables to pass them to success page.
$_SESSION['couples_url'] = $couples_url;
// If working in root directory.
$_SESSION['couples_path'] = str_replace('.', '', $couples_path);
// If working in a sub directory.
//$_SESSION['couples_path'] = substr_replace($base_path, '', -1).str_replace('.', '',$couples_path);

header('Location: success.php');

?>
Comment

PREVIOUS NEXT
Code Example
Php :: provenienza geografica di un utente php webmaster 
Php :: mr deepfakes forum 
Php :: laravel collect whereNotIn not working 
Php :: Google Dorks Using special search string for Web Server Detection 
Php :: Downward half-Pyramid Pattern of Star 
Php :: searching for new lines 
Php :: show dot dot after some words php 
Php :: saleor meaning 
Php :: laravel where has relation 
Php :: laravel model retrieve 
Php :: codeigniter round off function 
Php :: checnge message no products were found matching your selection woocommerce edit 
Php :: most sites visited by ip address laravel 
Php :: Multiple Formats with PHP DateTime::createFromFormat() 
Php :: null php 
Php :: laravel validate string 
Php :: apache/2.4.52 (win64) openssl/1.1.1m php/8.1.2 server at localhost port 80 
Php :: laravel facade 
Php :: stripslash 
Php :: wp site url link from admin 
Php :: variable superglobale php 
Php :: dateinterval hh mm ss 
Java :: import collectors java 
Java :: how to set current date in android studio 
Java :: how java programm actually run 
Java :: java pause 1 second 
Java :: java check if number is even 
Java :: java get current milliseconds 
Java :: bukkit event list 
Java :: array to map java4 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =