472,146 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Add href= tag to echo

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
Jul 17 '05 #1
9 35251
Robertico <Ro*******@nospam.notvalid> wrote:
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>";


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 ")
Jul 17 '05 #2
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
Jul 17 '05 #3
> echo "<b>$name</b>,<br>Sorry there's a problem sending your message. Please
try <a href="/mail.html">again</a>";

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
Jul 17 '05 #4
Thx.

I 'am learning php :-))
Jul 17 '05 #5
Robertico <Ro*******@nospam.notvalid> wrote:
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>";


Yes :)

Though the javascript URL is a horrible pratice.
Jul 17 '05 #6
> Though the javascript URL is a horrible pratice.

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

Robertico
Jul 17 '05 #7
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

Jul 17 '05 #8
Robertico <Ro*******@nospam.notvalid> wrote:
Though the javascript URL is a horrible pratice.


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


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

Jul 17 '05 #9
On 2005-07-15, Robertico <Ro*******@nospam.notvalid> wrote:
Though the javascript URL is a horrible pratice.


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


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

Jul 30 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by The Plankmeister | last post: by
2 posts views Thread by Adam Carolla | last post: by
1 post views Thread by wannieb | last post: by
2 posts views Thread by eholz1 | last post: by
2 posts views Thread by Breana | last post: by
5 posts views Thread by gothingarn | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.