Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to get code to be visible on a web page

    Hi,

    I want to show visitors to my site the code they need to use to make a link to my site.

    Trouble is - when i use the code, it is converted into a link - i want the actual code for the link to be visible on the webpage so the visitor can copy it.

    Any help appreciated.

    Thanks.

  • #2
    Regular Coder
    Join Date
    Jan 2009
    Posts
    173
    Thanks
    5
    Thanked 12 Times in 11 Posts
    Are you talking about the URL to your website?

    use php to get and display it:
    Code:
    <php>
    $url = "http://" . $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    
    echo  $url;
    
    </php>
    or echo it into an input field:

    Code:
    <form>
    <input type="text" value="<?php echo $url; ?>" />
    </form>

  • #3
    New Coder
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've not used php before and i've tried the form code you mentioned but it doesn't seem to work.

    The exact code i want to appear on the page is:

    <p>We're a partner of <a href="http://www.findashopfitter.co.uk" target="_blank">Findashopfitter.co.uk for (insert your county or counties here).</a></p>

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,951
    Thanks
    9
    Thanked 724 Times in 718 Posts
    Or, if you don't want to mess with php, then you need to convert the < and > symbols to their html equivalents - then the page will show the code not a link.

    So, to display:<a href="mylink">Link text</a>

    you need the following on your page:

    Code:
    &lt;a href="mylink"&gt;Link text&lt;/a&gt;
    You'll see that < is replaced by &lt; and > by &gt; (less than and greater than symbols)

  • #5
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    The easiest way is to use a text area or input like stated above that is what most sites do.
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #6
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Code:
    <textarea><a href="index.html">me</a></textarea>
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #7
    Regular Coder
    Join Date
    Jan 2009
    Posts
    173
    Thanks
    5
    Thanked 12 Times in 11 Posts
    Sorry, i made a few mistakes in the last post. It works now:

    Code:
    <?php
    
    $url = "http://" . $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    
    echo "<form>";
    echo  "<input type='text' value='" . $url . "' />";
    echo "</form>";
    
    ?>

  • #8
    New Coder
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    cool - got it working. Thanks all.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •