When I run this, the hyperlink comes out in text. How do I make the hyperlink come out live?

<?php>

$pc = $_POST['pc'];

If ($pc == 0) {
$pcText = "http://www.yahoo.com";
}

else if ($pc == 1) {
$pcText = "http://www.google.com";
}

?>

<p>Website: <?php echo $pcText ?> </p>

    You need to stick it inside an A tag, e.g.:

    <p>Website: <a href='<?php echo $pcText; ?>'><?php echo $pcText; ?></a>
    

    Or any of a dozen other styles of outputting text that PHP allows. 🙂

      Hi,
      It is better to add double quotes to the href URL.

      <p>Website: <?php echo '<a href="'. $pcText. '">'. $pcText. '</a>'; ?></p>
        CoursesWeb;11013815 wrote:

        Hi,
        It is better to add double quotes to the href URL.

        <p>Website: <?php echo '<a href="'. $pcText. '">'. $pcText. '</a>'; ?></p>

        What's wrong with single quotes? (It's part of the [X]HTML standard, and I've never heard of a browser that acted differently depending on whether you wrap attribute values in single or double quotes.)

          5 days later

          NogDog, I think that's it's more that it's the norm than any necessity. I know that I use double quotes in all my HTML, and single quotes in Javascript, which works well together when mixing the two, but there's no reason to do one over the other except for just getting into a habit.

            I've actually developed the habit of using single quotes, so that I can use double quotes around the entire PHP string and do variable interpolation. But like you say, it's all a matter of preference and style, and how much typing back-slashes bothers you. 😉

              I use all single quotes with concatenation, or heredoc syntax for large blocks. I absolutely, positively HATE seeing slashes unless it followed by on of (r,n,t). But again its personal preference and habit. If someone offered me a job tomorrow that was an upgrade (aka I got to work with php instead of .net) and told me they do all double quotes in php, html and javascript so I better learn to slash, I would start doing it in a heartbeat =D

                Derokorian;11014277 wrote:

                all double quotes in php, html and javascript so I better learn to slash, I would start doing it in a heartbeat =D

                And in a heartbeat, I'd create a function to simply return the string with escape double quotes and use sprintf 🙂
                More typing, but at least then things remain readable.

                Personally I prefer if things are consistent. Either all sq or all dq for html attributes. Simply because it reduces typing when searching for attribute values
                =('|")[\1]+?\1

                  Write a Reply...