php动态生成链接,如何使用PHP动态生成HTML页面?

我一直在做类似的工作,我有一些可能对你有帮助的代码。实例是here及以下,是我用来作为参考的代码。

创建-page.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');

?>希望这个文件可以帮助并作为参考来启动和提升你的项目。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值