Confusing Functions


Posted on 16th Feb 2014 07:03 pm by admin

So, I've been reading up on Functions and I like them! However, I need some help using variables in functions, since it's kind of confusing.

I just made these functions:

<?php

function Protect($var){
$var = mysql_real_escape_string(htmlentities(stripslashes($var)));
}

function Preserve($var){
$content = nl2br(str_replace(" ", "&nbsp;", $var));
}
?>


Neither of them work. Dunno why.

From what I understand...

If I do this:
function HelloThere($var){

Then when I use the function I can go...
HelloThere($hello);

And the $hello variable will be substituted for $var from when I defined the function. Am I not right, confusing, or misled? Please help!!!

Thanks.


PS I originally had this, but it didn't work:
<?php

function Protect($var){
$variable = $var;
$protect1 = mysql_real_escape_string($variable);
$protect2 = htmlentities($protect1);
$protect3 = stripslashes($protect2);
}

function Preserve($var){
$content = nl2br(str_replace(" ", "&nbsp;", $var));
}
?>

No comments posted yet

Your Answer:

Login to answer
199 Like 21 Dislike
Previous forums Next forums
Other forums

i need help with php header and footer
I have designed a header and footer for my site and they seem to be ok when they are running individ

Pop-up Banner
Hello Friends,I need to use banner in our client site.Example: www.example.com if i enter this site

PHP SUBMIT
Code: <input name="doLogin" type="image" src="images/loginsubmit.jpg

Login Script Issues
I am using a script I got from http://phpsense.com/php/php-login-script.html in order to allow peopl

PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi

Not reloading page after php form submit
Hello helpful souls out there. You guys have come through for me in the recent past and I'm hoping s

Losing 'page' data
I have this code that allows me to update my database. But after updating, I lose the $_GET['page']

Locking mysql tables with php
Hi

BACKGROUND:
I have multiple instances of the same php script running in a WAMP environ

firefox wouldnt stream mp3 files completely from my php page
hi everyone,
I have a php file trying to read and stream mp3 files. It works fine in IE but my pr

I need desperate help with this php code integrated with flash please
Can someone please help me with this php code which I have been stuck on for weeks . I am trying to

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash