Allowing people to take html tag

design

#1

Hello there. I had a quick question. I wanted to allow people on my website to copy an html tag (this way they can put my banner on their websites). Nevertheless, I am not sure what the best way is to display the tag on my page. Would anyone have any advice?


#2

Some people put the tag in textarea.

With javascript, text in textarea can be automatically highlighted when user clicks on it.

Another way may be replacing “<” with “& lt;” using PHP function
preg_replace("<", “& lt;”, $yourtag);

no space between “&” and “lt;”

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


#3

Thank you very much for your response!

I would like to place it in a text area, I think that would look cleaner. Would you have any advice on the best way to do this?


#4

[quote]Another way may be replacing “<” with “& lt;” using PHP function
preg_replace("<", “& lt;”, $yourtag);[/quote]
Two things:

  1. You’d be off using htmlentities() for this. It’ll catch all HTML that needs transformation, not just left brackets, and is probably more efficient than your regex.
  2. The regex you do show has a syntax error. In the match part of preg_replace (the first param), you need to add delimiters to the regex. It should look like preg_replace("/</", “<”, $yourtag);

This page describes the technique in what I think is a fairly straightforward way. If you don’t want a special button for selecting the text, but would rather users can simply click the textarea, the onclick handler (in red) can be made an attribute of the textarea like so: onClick="javascript:select();"*

Another option, which I think is a lot better because of its semantic clarity, is to use ranges to select text inside a element. It’s a harder technique which isn’t easily supported across browsers, unfortunately, so I hesitate to recommend it. You would use it in much the same way as the textarea.


#5

Excellent advice. Thank you!!!


#6

I tried but failed to recall this function. :frowning:

You are right. It is my mistake. I think I found the reason why I always generate bugs :stuck_out_tongue:

Hey, I found out the trick how to post html entities. :slight_smile:

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here