theloveforphp Posted November 22, 2011 Share Posted November 22, 2011 Hey! I have a small code where I want to check if one variable matches the other when the other is sent through a function. The function, for practical reasons, is included with a separate PHP-file. And I cant seem to apply a variable to the function which processes the other variable. Its really wierd to me. Here is the code for the main PHP-file: <?php include 'function.php'; $unformatted = "FORMATTING AY ..."; $formatted1 = "formattingay..."; $formatted2 = test_format($unformatted); if ($formatted1 == $formatted2) { echo "Success, formatted!"; } else { echo "Fail, unformatted."; } ?> And here is the code for "function.php": <?php function test_format($var) { strtolower(str_replace(array(" "), array(""), $var)); } ?> Does anybody have a clue to why this simply wont work? Any answers and help is highly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/251599-problem-usingreaching-included-function/ Share on other sites More sharing options...
pocetong Posted November 22, 2011 Share Posted November 22, 2011 My english is very poor,so I may not speak very clearly. Your error is function.php.You forget "return" <?php function test_format($var) { return strtolower(str_replace(array(" "),array(""),$var)); } ?> If my answer is wrong ,you send email to [email protected] for telling me. Quote Link to comment https://forums.phpfreaks.com/topic/251599-problem-usingreaching-included-function/#findComment-1290338 Share on other sites More sharing options...
theloveforphp Posted November 22, 2011 Author Share Posted November 22, 2011 My english is very poor,so I may not speak very clearly. Your error is function.php.You forget "return" <?php function test_format($var) { return strtolower(str_replace(array(" "),array(""),$var)); } ?> If my answer is wrong ,you send email to [email protected] for telling me. Thats the thing, I dont want the function to echo the result as default. If I use "return" it will automatically echo the formatted value/variable and I want to be able to use it in a if-expression, which I cant if its echoing. Quote Link to comment https://forums.phpfreaks.com/topic/251599-problem-usingreaching-included-function/#findComment-1290347 Share on other sites More sharing options...
pocetong Posted November 22, 2011 Share Posted November 22, 2011 Sorry,I am chinese.My English is very poor!! If you want use the function test_format() echoing = the function strtolower()=string strtolower ( string $str ).................... Quote Link to comment https://forums.phpfreaks.com/topic/251599-problem-usingreaching-included-function/#findComment-1290356 Share on other sites More sharing options...
trq Posted November 22, 2011 Share Posted November 22, 2011 Thats the thing, I dont want the function to echo the result as default. If I use "return" it will automatically echo the formatted value/variable and I want to be able to use it in a if-expression, which I cant if its echoing. return does not produce output. Quote Link to comment https://forums.phpfreaks.com/topic/251599-problem-usingreaching-included-function/#findComment-1290367 Share on other sites More sharing options...
theloveforphp Posted November 22, 2011 Author Share Posted November 22, 2011 Thats the thing, I dont want the function to echo the result as default. If I use "return" it will automatically echo the formatted value/variable and I want to be able to use it in a if-expression, which I cant if its echoing. return does not produce output. It doesnt? Hmm, I must have missed something in my testing, it seems to work fine now. Thats odd because I tried the exact same thing yesterday and it echoed the formatted value. Anyhow, I'll mark this as solved and test it a bit further. Thanks to you both for the help! Quote Link to comment https://forums.phpfreaks.com/topic/251599-problem-usingreaching-included-function/#findComment-1290383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.