Forum Moderators: open

Message Too Old, No Replies

Offering PHP snippet in textarea

Allowing users to copy include code to their site

         

wheelie34

9:55 am on Mar 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I offer a widget to other users all they need to do is copy a snippet of code, paste it into their page and it displays a widget from my site which is updated every 40 minutes.

I want to put the code into a textarea so they can click copy paste into their site using onClick to highlight all. I have made 2 versions one as an iframe for html pages (works fine in textarea) the other a php include, incase they have a php page, this code actually calls the include page within the textarea, I dont want that to happen, I just want it to show the code as text.

How do I go about it, thanks in advance

penders

12:44 pm on Mar 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you need to encode the '<' and '>' characters in your code snippet (within your textarea in your HTML source) in order to prevent it from being parsed as PHP. ie. encode them as &lt; and &gt; respectively.

If you are outputting your page with PHP, you can do this with a call to htmlspecialchars() to convert special characters into HTML entities.
[uk.php.net...]

wheelie34

1:15 pm on Mar 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks penders, that worked perfect.