garyblackpool Posted September 14, 2009 Share Posted September 14, 2009 The sever which i am using runs on php5 so i think the problam is with the syntax. I keep on getting Fatal error: Function name must be a string. Could you please help cos been searching but have not been able to find anyting thanks. <form method="post" action="display_input.php"><p><strong> Text Field</strong><br><textarea name="text" cols=45 rows=5 wrap=virtual></textarea></p><p><strong>String Functions</strong></br><input type="radio" name="func" value="md5" checked> get md5<br><input type="radio" name="func" value="strlen" checked> length of string<br><input type="radio" name="func" value="strrev" checked>reverse string<br><input type="radio" name="func" value="strtoupper" string uppercase<br><input type="radio" name="func" value="strtolower" checked>string lowercase3<br><input type="radio" name="func" value="ucwords" checked>first letter capital<br></p><p><input type="submit" name="submit" value="do Something with the String"><p></form> And this is the other file <?$func = $POST_["func"];$text1 = $POST_["text1"];$result = $func($text1); ?><html><head<title> Generic Input Results</title></head><body><? echo "$result"; ?><p><a href="generic_form.html">Go again!</a><p></body><html> Thanks for any help Link to comment Share on other sites More sharing options...
Ingolme Posted September 14, 2009 Share Posted September 14, 2009 It's $_POST, not $POST_. So $func is undefined and therefore is not a string. Link to comment Share on other sites More sharing options...
garyblackpool Posted September 14, 2009 Author Share Posted September 14, 2009 It's $_POST, not $POST_. So $func is undefined and therefore is not a string.Oh wow thanks been trying to figure it out for ages. The post bit has worked just need to fingure out how to define a varible thanks x Link to comment Share on other sites More sharing options...
jeffman Posted September 14, 2009 Share Posted September 14, 2009 I'll be surprised if your setup will work. $_POST["func"] will be parsed as a string, not a function reference. You may need to add an eval() statement in there. The following works, for example: <?php $str = 'hello'; $func="strlen"; $L= eval("return $func($str);"); echo $L;?> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 14, 2009 Share Posted September 14, 2009 This will work also: $str = 'hello';$func="strlen";echo $func($str); PHP's weird like that. It also works to just use the function reference: <?php$str = 'hello';$func="strlen";echo $func($str);$func = strlen;echo $func($str);?> both of those will run strlen. Link to comment Share on other sites More sharing options...
jeffman Posted September 14, 2009 Share Posted September 14, 2009 I really played around with this, but somehow I tried everything BUT the obvious. I've been wondering why there wasn't a way to explicitly cast a string to an object. Implicit works just fine. Link to comment Share on other sites More sharing options...
garyblackpool Posted September 14, 2009 Author Share Posted September 14, 2009 Oh I am sort of getting it. I got the code from a php 4 book so perhaps learning from php4 book is not the way to go. thanks Link to comment Share on other sites More sharing options...
jeffman Posted September 15, 2009 Share Posted September 15, 2009 Naah. You can learn a lot from a PHP4 book. Most ver. 5 features that you'll need you can get from the online manual. You've seen that, right? http://www.php.net/manual/en/index.phpI use it all the time. Link to comment Share on other sites More sharing options...
garyblackpool Posted September 15, 2009 Author Share Posted September 15, 2009 Naah. You can learn a lot from a PHP4 book. Most ver. 5 features that you'll need you can get from the online manual. You've seen that, right? http://www.php.net/manual/en/index.phpI use it all the time.Yes I have looked through the manual but it does seem to be rather confusing. Still have not figured how to formate the form on the results page. cheerz Link to comment Share on other sites More sharing options...
PravinBhat Posted October 12, 2009 Share Posted October 12, 2009 In the Action part... I mean the page being displayed after you click SubmitHAVe A look at this$func = $POST_["func"];Chang it to $func = $POST_['func']; Link to comment Share on other sites More sharing options...
justsomeguy Posted October 12, 2009 Share Posted October 12, 2009 The correct variable is $_POST, not $POST_. It doesn't matter if single or double quotes are used for this. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.