Php snippets?

Page 1 of 1

7 Replies - 951 Views - Last Post: 31 August 2008 - 05:01 AM Rate Topic: -----

#1 nutter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 03-November 07

Php snippets?

Posted 30 August 2008 - 02:04 PM

Ok i have a script made by me and a friend its a new system but when we try to post php code like <?php echo "hi"; ?> it parses and we use <code> still prses is there a way to stop this and make it see'able? thanks,
Is This A Good Question/Topic? 0
  • +

Replies To: Php snippets?

#2 chili5   User is offline

  • D.I.C Lover

Reputation: 20
  • View blog
  • Posts: 1,146
  • Joined: 28-December 07

Re: Php snippets?

Posted 30 August 2008 - 02:10 PM

Not really sure what your asking? If your trying to put PHP code on your web site you can use:

<?php
highlight_string("<?php echo \"Hello\"?>");
?>


Was This Post Helpful? 0
  • +
  • -

#3 nutter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 03-November 07

Re: Php snippets?

Posted 30 August 2008 - 02:18 PM

ok il explain more clear

our code adds info from a textbox to a db then prints on index page

but if we try to add php to the mysql db it doesnt display it executes same with javascript
Was This Post Helpful? 0
  • +
  • -

#4 Moonbat   User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 424
  • Joined: 30-June 08

Re: Php snippets?

Posted 30 August 2008 - 02:37 PM

Before adding the text to your DB, use str_replace() to replace signs like <, >, ?, etc. with the HTML character equivalent

For a character chart, go here - http://www.tntluoma....sidebars/codes/
Was This Post Helpful? 0
  • +
  • -

#5 nutter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 03-November 07

Re: Php snippets?

Posted 30 August 2008 - 02:41 PM

thnaks you
Was This Post Helpful? 0
  • +
  • -

#6 nutter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 03-November 07

Re: Php snippets?

Posted 31 August 2008 - 04:12 AM

Yet anougher problem :(
it works with <?php ?> but not for <script>

Heres my code
<?php
$var = $_POST['text'];
$things = array("<?php","?>","<script>");
$newthings = array('&lt?php','?&gt','&ltscript&gt');
$out = str_replace($things,$newthings,$var);
echo $out;
?>

Was This Post Helpful? 0
  • +
  • -

#7 realNoName   User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 04-December 06

Re: Php snippets?

Posted 31 August 2008 - 04:29 AM

php has a few functions to remove / change special characters from a string, take a look at htmlspecialchars() to convert special characters to HTML entities and htmlspecialchars_decode() to convert special HTML entities back to characters
Was This Post Helpful? 1
  • +
  • -

#8 nutter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 03-November 07

Re: Php snippets?

Posted 31 August 2008 - 05:01 AM

Thank You it works fine now :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1