newtophp59 Posted March 2, 2011 Share Posted March 2, 2011 I created a function called converter. My code doesn't look like it processes anything after the first if . This is what is displayed in browser. Convert a String original string: roses Are red, violets are blue.... converted string: roses are red, violets are blue.... converted string: roses are red, violets are blue.... converted string: roses are red, violets are blue.... <html> <head> <title>Create a PHP Function to Convert a String</title> </head> <body bgcolor="pink"> <h2>Convert a String</h2> <?php $phrase = "roses Are red, violets are blue...."; function converter($arg1, $arg2){ if($arg1="lower"){ return strtolower($arg2); } elseif ($arg1="upper"){ return strtoupper($arg2); } else /* if($arg1="title")*/{ return ucwords($arg2); } } print "original string: ".$phrase."<br />"; print "converted string: ".converter("upper",$phrase)."<br />"; print "converted string: ".converter("lower",$phrase)."<br />"; print "converted string: ".converter("title",$phrase)."<br />"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/229346-calling-a-function-doesnt-return-expected-results/ Share on other sites More sharing options...
QuickOldCar Posted March 2, 2011 Share Posted March 2, 2011 you would want 2 == to do the check make this: if($arg1="lower"){ return strtolower($arg2); } elseif ($arg1="upper"){ return strtoupper($arg2); } else /* if($arg1="title")*/{ return ucwords($arg2); } into this: if($arg1=="lower"){ return strtolower($arg2); } elseif ($arg1=="upper"){ return strtoupper($arg2); } else /* if($arg1=="title")*/{ return ucwords($arg2); } Link to comment https://forums.phpfreaks.com/topic/229346-calling-a-function-doesnt-return-expected-results/#findComment-1181710 Share on other sites More sharing options...
newtophp59 Posted March 2, 2011 Author Share Posted March 2, 2011 Mucho Thanks to Quick Old car.... I must have been brain dead last night....You are fabulous Link to comment https://forums.phpfreaks.com/topic/229346-calling-a-function-doesnt-return-expected-results/#findComment-1181940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.