Page 1 of 1

highlight_string()

Posted: Thu Sep 16, 2004 9:55 am
by Getran
Hey there,

I wanted to display PHP code like used on these forums (the old version though) and i found a function called highlight_string() which i thought worked perfect to what i wanted. When i tried it i found out that no matter what i do, if u put a var in it, eg highlight_string("$_REQUEST['var']");, all that it shows is either the contents of the var if it is set elsewhere on the page (eg On my site i use index.php?p=tutorials, then i wanted to make a tutorial of how i did them, but if i put if (isset($_REQUEST['p'])) it replaces it with 'tutorials'). Also if the var has no value (i tried just using $page instead) it just displays nothing.

Is there anyway to fix this ? or should i find a different way of doing it ?

Thx

// Getran

Posted: Thu Sep 16, 2004 10:19 am
by John Cartwright
You can do a few things, try simply using single quotes so the vars are treated as a string...

Posted: Thu Sep 16, 2004 10:49 am
by Getran
if you use the quotes inside the highlight_string() function it just actually displays the quotes..

Posted: Thu Sep 16, 2004 10:57 am
by John Cartwright
show us what you have so far

Posted: Fri Sep 17, 2004 12:34 pm
by Getran
sorry for late reply but i wasn't available to access comp. Here is what i'm using, and trying to display.

Code: Select all

<?
highlight_string("<?
if (isset($_REQUEST['p']))
{
  $inc = $_REQUEST['p'].".inc";
  if (!file_exists($inc))
  {
     echo "File not found";
  }
  else
  {
     include($inc);
  }
}
else
{
  include("index.inc");
}
?>");
?>
atm, all that it puts out is:

Code: Select all

&lt;?
if (isset())
&#123;
  = .".inc";
  if (!file_exists())
  &#123;
     echo "File not found";
  &#125;
  else
  &#123;
     include();
  &#125;
&#125;
else
&#123;
  include("index.inc");
&#125;
?&gt;

Posted: Fri Sep 17, 2004 12:39 pm
by markl999
Just tweak the quotes (as mentioned above).

Code: Select all

<?php

highlight_string('<?
if (isset($_REQUEST[''p'']))
{
  $inc = $_REQUEST[''p''].".inc";
  if (!file_exists($inc))
  {
     echo "File not found";
  }
  else
  {
     include($inc);
  }
}
else
{
  include("index.inc");
}
?>');

?>