简体   繁体   中英

PHP Echo information and wait to remove it

What I'm trying to do in my code is show a set of numbers, wait for a specified amount of time, and then delete what was previously shown, and then show an input. I just started coding recently.

if(isset($_POST['Start'])){
ob_clean();
echo $num2;
sleep(2);
ob_clean();
echo "<form method='post' action=''>
(etc...)

If data has been sent to browser, php can't impact it. My solution is when you show your input, you attached a javascript function. okay, i thinks this code will help you

<?php 
function flush_buffers(){ 
    //This function make buffer send with out some problem
    ob_end_flush(); 
    ob_flush(); 
    flush(); 
    ob_start(); 
} 
ob_start();
$title = "<span class='mytitle'>My Title</span>";
echo $title; //You send your information
flush_buffers();

$input = "<input type='text'>"
$js_code = "<script type='text/javascript'>$('.mytitle').remove()</script>";//with jQuery :)
echo $input.$js_code;
flush_buffers();
 ?>

Try this:

if(isset($_POST['Start'])){
ob_clean();
echo $num2;
sleep(2);
ob_clean();
header('Location: '.$_SERVER['PHP_SELF']);
die;
} else {
echo "<form method='post' action=''>
(etc...) }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM