将变量从PHP传递到HTML

将变量从PHP传递到HTML

本文介绍了将变量从PHP传递到HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面, play.html :

 < ; form method =postaction =play.php> 
< input type =hiddenname =mp3namevalue =/ MP3 / 1.mp3>
< input type =submitvalue =Play My MP##1/>
< / form>


< form method =postaction =play.php>
< input type =hiddenname =mp3namevalue =/ MP3 / 2.mp3>
< input type =submitvalue =Play My MP##2/>
< / form>

这会调用另一个页面, play.php :

 <?php 

$ formurl =play.html;
$ playerurl =player.html;

$ mymp3 = $ _GET [mp3name];

header(Location:$ playerurl?mp3name = $ mymp3);
出口;
?>

然后调用另一个页面< player.html :

 < audio id =playersrc =$ mymp3autoplay preload =auto> < /音频> 
< div>
< button onclick =document.getElementById('player')。play()>播放< / button>
< button onclick =document.getElementById('player')。pause()>暂停< /按钮>
< button onclick =document.getElementById('player')。volume + = 0.1>增大音量< /按钮>
< button onclick =document.getElementById('player')。volume- = 0.1> Volume Down< / button>
< / div>

如何将一个变量从PHP传递给 player.html

解决方案

您正在获取 $ mymp3 在使用< form method ='post'.. 时将 $ _ GET 更改为;

然后,将您的player.html扩展名更改为player.php以使用PHP代码就可以了。



所以,当你有你的player.php文件时,改变这个...

 < audio id =playersrc =$ mymp3autoplay preload =auto> < /音频> 

至此...

 < audio id =playersrc =<?php echo $ mymp3?> autoplay preload =auto> < /音频> 


I have a page, play.html:

    <form method="post" action="play.php">
         <input type="hidden" name="mp3name" value="/MP3/1.mp3">
         <input type="submit"  value="Play My MP# #1" />
    </form>


<form method="post" action="play.php">
    <input type="hidden" name="mp3name" value="/MP3/2.mp3">
    <input type="submit"  value="Play My MP# #2" />
</form>

This calls another page, play.php:

<?php

$formurl = "play.html" ;
$playerurl = "player.html" ;

$mymp3 = $_GET["mp3name"];

header( "Location: $playerurl?mp3name=$mymp3" );
exit ;
?>

Then it calls another page, player.html:

<audio id="player" src="$mymp3" autoplay preload="auto"> </audio>
       <div>
       <button onclick="document.getElementById('player').play()">Play</button>
       <button onclick="document.getElementById('player').pause()">Pause</button>
       <button onclick="document.getElementById('player').volume+=0.1">Volume Up</button>
       <button onclick="document.getElementById('player').volume-=0.1">Volume Down</button>
          </div>

How do I pass a variable from PHP to player.html?

解决方案

You are getting the variable $mymp3 with $_GET while you are using <form method='post'.., change it to $mymp3 = $_POST['mp3name'];

Then, change your player.html extension to player.php to use PHP code on it.

So, when you have your player.php file, change this...

<audio id="player" src="$mymp3" autoplay preload="auto"> </audio>

to this...

<audio id="player" src="<?php echo $mymp3 ?>" autoplay preload="auto"> </audio>

这篇关于将变量从PHP传递到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:26