Add href= tag to echo

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robertico

    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">agai n</a>";

    Robertico


  • Daniel Tryba

    #2
    Re: Add href= tag to echo

    Robertico <Robertico@nosp am.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">agai n</a>";[/color]

    Yes, it's possible. But your single line of code is flawed. You should
    really find out how strings work in PHP:

    (pay attention to escaping and the use of ' and ")

    Comment

    • Robertico

      #3
      Re: Add href= tag to echo

      Is this better ?

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

      Robertico


      Comment

      • Hilarion

        #4
        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">agai n</a>";[/color]


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

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


        Hilarion

        Comment

        • Robertico

          #5
          Re: Add href= tag to echo

          Thx.

          I 'am learning php :-))


          Comment

          • Daniel Tryba

            #6
            Re: Add href= tag to echo

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

            Yes :)

            Though the javascript URL is a horrible pratice.

            Comment

            • Robertico

              #7
              Re: Add href= tag to echo

              > Though the javascript URL is a horrible pratice.

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

              Robertico


              Comment

              • BKDotCom

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

                Comment

                • Daniel Tryba

                  #9
                  Re: Add href= tag to echo

                  Robertico <Robertico@nosp am.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).

                  Comment

                  • richard

                    #10
                    Re: Add href= tag to echo

                    On 2005-07-15, Robertico <Robertico@nosp am.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=\"somethin g\">Somewhere </a>";
                    print '<a href="somthing" >'.$sData."</a>\n";

                    Comment

                    Working...