2011-12-21 15 views
-2

我是PHP的新手,我需要知道如何在頁面上顯示輸入的數據。我會澄清。在頁面上有一個文本框,當用戶在其中鍵入內容並點擊提交時,會出現一個空白頁面,內容爲:您輸入了[輸入數據]。我想這樣做,所以我把一個代碼放在文本框中,它會自動生成正確的iframe。PHP - 使腳本顯示輸入的數據

<iframe marginwidth="0" marginheight="0" src="http://jb-radio.com/movies/play.php?mu=[ENTERED DATA HERE]" frameborder="0" height="360" scrolling="no" width="640"></iframe>

請在這個腳本(我認爲這是用PHP做)我想這應該是相當簡單的幫助。

回答

0

可以在客戶端Javascript,沒有涉及PHP這樣做:

<iframe id="the_iframe" style="display:none;" marginwidth="0" marginheight="0" src="" frameborder="0" height="360" scrolling="no" width="640"></iframe> 

<input id="the_input" type="text" /> 
<input id="the_button" type="button" value="Click me to change the iframe" /> 

<script type="text/javascript"> 
    document.getElementById('the_button').onclick = function() { 
    var theUrl = 'http://jb-radio.com/movies/play.php?mu='; 
    theUrl = theUrl + document.getElementById('the_input').value; 
    var theIframe = document.getElementById('the_iframe'); 
    theIframe.style.display = 'block'; 
    theIframe.src = theUrl; 
    }; 
</script> 

Try it out

+0

看起來不錯!有沒有什麼辦法,而不是創建iframe,它會輸出iframe代碼? – psl101 2011-12-21 14:34:07

+0

是的,看[這個小提琴](http://jsfiddle.net/93yPT/2/) – DaveRandom 2011-12-21 14:45:37

+0

謝謝!!!!!! – psl101 2011-12-21 14:47:26

0

創建和使用表單是一個相當基本的主題。使用Google查找一些簡介php課程。我開始時使用了tizag。您的解決方案將涉及使用$ _POST或$ _GET超全局(取決於表單方法)。

0

這裏是你如何從一個URL

url = "http://www.example.com/test.php?example_id=123" 

$id_1 = $_GET['example_id']; //equals 123 from the URL parameter 

獲取參數值設置你的iframe網址,你將需要包括$ ID

<iframe marginwidth="0" marginheight="0" src="http://jb-radio.com/movies/play.php?mu=<?php $id ?>" frameborder="0" height="360" scrolling="no" width="640"></iframe> 

這是假設你的頁面使用.php擴展名而不是.html。如果你想使用.html頁面,你的服務器需要能夠解析.php文件。

相關問題