如何在echo PHP函数中显示此HTML字符串 [英] How to display this HTML string in echo php function
问题描述
我是php的新手...我有一个将用户名变量传递给php scrit的表单,这是代码。.
< form action = bottone .php method = get>输入法:<输入名称=用户名 type =文本 /> <输入type = submit value = GENERA CODICE /> < / form>
I'm a newbie in php... I have a form who pass a username variable to a php scrit, this is the code..
<form action="bottone.php" method="get"> Inserisci il tuo nome utente: <input name="username" type="text" /> <input type="submit" value="GENERA CODICE" /> </form>
我想在botton.php脚本中显示以下HTML代码:
I would like to display this HTML code in the botton.php script:
<a href=www.mysite.com/$username <img src="http://www.mysite.com/images/logo.jpg" width="50" height="50" alt="La mia pagina su Mysite"/></a>
其中$ username是从表单传递的变量...我该如何用echo做到这一点功能??
谢谢
where $username is the variable passed from the form... how can I do that with an echo function?? Thanks
推荐答案
像这样:
<?php
echo '<a href="http://www.mysite.com/'.$username.'"><img src="http://www.mysite.com/images/logo.jpg" width="50" height="50" alt="La mia pagina su Mysite"/></a>';
?>
或者,像这样:
<a href="http://www.mysite.com/<?=$username?>"><img src="http://www.mysite.com/images/logo.jpg" width="50" height="50" alt="La mia pagina su Mysite"/></a>
您可能需要确保$ username是安全的,但至少要使用 urlencode , htmlspecialchars 或类似的内容。
You may want to make sure $username is safe though... at least use urlencode, htmlspecialchars, or something similar.
* EDIT > *
我假设您已经知道如何从您提到的表单中获取$ username,但是如果您不知道,则可以这样做:
*EDIT* I had assumed you already knew how to get $username from the form you mentioned, but in case you didn't, you would just do:
$username = $_GET['username'];
或者您可以以此为契机使用上面提到的那些功能(除非您需要
Or you could use this as an opportunity to use those functions I mentioned above (unless you will be needing $username for some other purpose before echoing it out.
示例:
$username = urlencode($_GET['username']);
或者您可以这样做直接在回声中像这样:
Or you could do this straight in the echo like this:
<a href="http://www.mysite.com/<?=urlencode($_GET['username'])?>"><img src="http://www.mysite.com/images/logo.jpg" width="50" height="50" alt="La mia pagina su Mysite"/></a>
这篇关于如何在echo PHP函数中显示此HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!