English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to echo a small script in php. But when i echo the script instead of it just showing the script thats in the echo it actually performs it. I know you can use ' ' to make the whole string literal but i also have variables in the echo string of which the values i want to be shown. ' ' dosnt show the variables. values. Does anyone know a script that shows the code without it performing but still have variables in the string which show their values.

Basically its for a news site, people select the script from my site, put it on theirs and news events are shown on their site.

2006-09-18 10:29:59 · 6 answers · asked by peter s 1 in Computers & Internet Programming & Design

6 answers

Many sites do this by putting the code as the default information within a textarea tag. This also allows you to limit the actual size of the box on the page so that long code does not mess with your look and feel. The textbox will be scrollable allowing full viewing and copying.

2006-09-18 10:36:55 · answer #1 · answered by Interested Dude 7 · 0 0

So you want a script like and show it on the screen??? with out actually returning the word hello on the screen as html?

If it is, there are two ways. One is to use the proper syntax of < and > which are (WITHOUT SPACES):
& lt ;
& gt ;

so the above php code is (again, & gt ; and & lt ; wihtout spaces):
& lt ;?php echo "Hello"; ?& gt ;

also, a hint on the & gt; look at this page source code, and you see what I mean!

or you can use something called pre tags
so you have






The pre tags, I am not sure if they are html valid. So check www.w3.com if you are fussy at making your code valid.

or if you want php code to generate php code.. use this

" ?>
The reason why this works is because php works by scaning the file and then performing operation and transforming the document into an html format. Because this statement performs a operation, by the time is has finish the operation, in this case the echo, that echo string is now in an html format, and not a php code. Simple.

2006-09-18 10:33:08 · answer #2 · answered by cktan86 2 · 0 0

You could also use the function highlight_file($fileToShow) to view the source code. Just make sure you don't echo any sensitive files.

2006-09-19 03:23:33 · answer #3 · answered by Anonymous · 0 0

echo('This will concatenate the values of the variables to the echo string' . $varname . 'The periods are used to concatenate (add) to a string in PHP!');

2006-09-18 10:39:56 · answer #4 · answered by Anonymous · 0 0

If you create a file, and based on mime type, name it phps, and put your snippet in there, then you should be able to have them click it and download it.... otherwise, just end the php statement and type the code. this is the code sample

2006-09-18 10:33:21 · answer #5 · answered by rar 2 · 0 0

Use highlight_file() instead of echo:

http://www.php.net/highlight_file

__________

2006-09-20 05:18:16 · answer #6 · answered by NC 7 · 0 0

fedest.com, questions and answers