Connecting Tech Pros Worldwide Forums | Help | Site Map

Add href= tag to echo

Robertico
Guest
 
Posts: n/a
#1: Jul 17 '05
Is it possible to add a "href=" tag to an echo line.

Something like this:
echo "<b>$name</b>,<br>Sorry there's a problem sending your message. Please
try <a href="/mail.html">again</a>";

Robertico



Daniel Tryba
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Add href= tag to echo


Robertico <Robertico@nospam.notvalid> wrote:[color=blue]
> Is it possible to add a "href=" tag to an echo line.
>
> Something like this:
> echo "<b>$name</b>,<br>Sorry there's a problem sending your message. Please
> try <a href="/mail.html">again</a>";[/color]

Yes, it's possible. But your single line of code is flawed. You should
really find out how strings work in PHP:
http://www.php.net/manual/en/language.types.string.php
(pay attention to escaping and the use of ' and ")
Robertico
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Add href= tag to echo


Is this better ?

echo "<b>$name</b>,<br><br>Sorry there's a problem sending your
message.<br> Please try ";
echo "<a href='javascript:history.back(1);'>again</a>";

Robertico


Hilarion
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Add href= tag to echo


> echo "<b>$name</b>,<br>Sorry there's a problem sending your message. Please[color=blue]
> try <a href="/mail.html">again</a>";[/color]


Yes. There are many ways. One of them is:

<html>
<?php
echo '<b>' . htmlspecialchars( $name ) . '</b>,<br />';
echo 'Sorry there's a problem sending your message. ';
echo 'Please <a href="/mail.html">try again</a>.';
?>
</html>

another:

<html>
<b><?php htmlspecialchars( $name ); ?></b>,<br />
Sorry there's a problem sending your message.
Please <a href="/mail.html">try again</a>.
</html>


Hilarion
Robertico
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Add href= tag to echo


Thx.

I 'am learning php :-))


Daniel Tryba
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Add href= tag to echo


Robertico <Robertico@nospam.notvalid> wrote:[color=blue]
> Is this better ?
>
> echo "<b>$name</b>,<br><br>Sorry there's a problem sending your
> message.<br> Please try ";
> echo "<a href='javascript:history.back(1);'>again</a>";[/color]

Yes :)

Though the javascript URL is a horrible pratice.
Robertico
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Add href= tag to echo


> Though the javascript URL is a horrible pratice.

Always interested in better solutions :-)) Please add one !

Robertico


BKDotCom
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Add href= tag to echo


BTW, the source of your original error was the the internal quotes.
if your string is surrounded by double quotes, it can't contain double
quotes (without escaping them - ie $string = "this \"is\" better";)
same goes with single quotes
$string = 'what\'s the deal';

unrelated: in my oppinion it's better to use single quotes

Daniel Tryba
Guest
 
Posts: n/a
#9: Jul 17 '05

re: Add href= tag to echo


Robertico <Robertico@nospam.notvalid> wrote:[color=blue][color=green]
>> Though the javascript URL is a horrible pratice.[/color]
>
> Always interested in better solutions :-)) Please add one ![/color]

Just like in your first post, a normal http url will always work. "Going
back" can have side effects (just see some recent discussions (just
generate a new form pre-populated with the data you just got)), there is
no guarantee that there is actually an URL to go back to (the action
could have been opened in a new tab/browser), javascript could have been
disabled (just look at all security advisories that suggest disabling
javascript as a (temporary) workaround).

richard
Guest
 
Posts: n/a
#10: Jul 30 '05

re: Add href= tag to echo


On 2005-07-15, Robertico <Robertico@nospam.notvalid> wrote:[color=blue][color=green]
>> Though the javascript URL is a horrible pratice.[/color]
>
> Always interested in better solutions :-)) Please add one !
>[/color]

print "<a href=\"something\">Somewhere</a>";
print '<a href="somthing">'.$sData."</a>\n";

Closed Thread