Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,177 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,153 people online right now. Registration is fast and FREE... Join Now!




Php snippets?

 
Closed TopicStart new topic

Php snippets?

nutter
30 Aug, 2008 - 01:04 PM
Post #1

New D.I.C Head
*

Joined: 3 Nov, 2007
Posts: 36


My Contributions
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,
User is offlineProfile CardPM
+Quote Post

chili5
RE: Php Snippets?
30 Aug, 2008 - 01:10 PM
Post #2

D.I.C Addict
****

Joined: 28 Dec, 2007
Posts: 763



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

php

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

User is offlineProfile CardPM
+Quote Post

nutter
RE: Php Snippets?
30 Aug, 2008 - 01:18 PM
Post #3

New D.I.C Head
*

Joined: 3 Nov, 2007
Posts: 36


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Moonbat
RE: Php Snippets?
30 Aug, 2008 - 01:37 PM
Post #4

D.I.C Regular
Group Icon

Joined: 30 Jun, 2008
Posts: 399



Thanked: 23 times
Dream Kudos: 600
My Contributions
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.com/sidebars/codes/
User is offlineProfile CardPM
+Quote Post

nutter
RE: Php Snippets?
30 Aug, 2008 - 01:41 PM
Post #5

New D.I.C Head
*

Joined: 3 Nov, 2007
Posts: 36


My Contributions
thnaks you
User is offlineProfile CardPM
+Quote Post

nutter
RE: Php Snippets?
31 Aug, 2008 - 03:12 AM
Post #6

New D.I.C Head
*

Joined: 3 Nov, 2007
Posts: 36


My Contributions
Yet anougher problem sad.gif
it works with <?php ?> but not for <script>

Heres my code
CODE

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

User is offlineProfile CardPM
+Quote Post

realNoName
RE: Php Snippets?
31 Aug, 2008 - 03:29 AM
Post #7

D.I.C Regular
***

Joined: 4 Dec, 2006
Posts: 311



Thanked: 5 times
My Contributions
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
User is offlineProfile CardPM
+Quote Post

nutter
RE: Php Snippets?
31 Aug, 2008 - 04:01 AM
Post #8

New D.I.C Head
*

Joined: 3 Nov, 2007
Posts: 36


My Contributions
Thank You it works fine now biggrin.gif
User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic
Time is now: 1/9/09 03:42AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month