undefinedfix
Sign in

PHP string splicing?

lypbm edited in Mon, 01 Aug 2022
if($res){
    echo "<script>alert('提交成功~!');
        location='../'.$qf;
        </script>";
}else{
    echo "<script>alert('提交失败 请稍后重试~!');
        location='../index.html'
        </script>";
}

$QF is a page address (similar to user.html )I want to achieve the data submitted to the database after the success of the jump to the splicing address, how to splice so no effect, ask the boss for advice

3 Replies
user620553
commented on Mon, 01 Aug 2022
echo "<script>alert('提交成功~!');location='../'".$qf.";</script>"

It is not recommended to use this method. Instead, sprintf series methods should be used to format the output. Secondly, it is not suitable to use echo to output multi line string directly.

Chuck
commented on Mon, 01 Aug 2022

Use sprintf to splice strings

sprintf("<script>alert('%s');location='%s';</script>","提交成功~!",$qf);
Rax
commented on Mon, 01 Aug 2022

Echo "< script > alert ('submitted successfully ~! ');location='../{$qf}';</script>"