Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display this HTML string in echo php function [duplicate]

Tags:

php

echo

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>

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>

where $username is the variable passed from the form... how can I do that with an echo function?? Thanks

like image 944
luca Avatar asked Nov 26 '25 10:11

luca


1 Answers

like this:

<?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>';
?>

Or, like this:

<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>

You may want to make sure $username is safe though... at least use urlencode, htmlspecialchars, or something similar.

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.

Example:

$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>
like image 55
mason81 Avatar answered Nov 29 '25 00:11

mason81



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!