Cause of "Method name must be a string" [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
public function run() {
$this->step = $this->$_POST("step", 1);
$this->xml = new XMLFile();
$common_data = array(
'STEPCONTENT' => $this->get_step_content(),
'STEPNUMBER' => $this->step,
'STEPTITLE' => $this->get_step_title()
);
echo $this->parse($this->common_template, $common_data);
This gives the exception:
Fatal error: Method name must be a string in
C:\xampp\htdocs\test\openad\install\InstallOpenAdServer.php on line 674
Why?

This is the culprit
$this->step = $this->$_POST("step", 1);
You cannot use an $_POST super global array as a function. If you are trying to access the vairable from the $_POST, you can simple do this
$this->step = $_POST["step"];

Related

I want Fibonacci string as concat string with previous 2 array element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
fibStr(3, ["j", "h"]) ➞ "j, h, hj"
fibStr(5, ["e", "a"]) ➞ "e, a, ae, aea, aeaae"
fibStr(6, ["n", "k"]) ➞ "n, k, kn, knk, knkkn, knkknknk"
I just want a function that returns a response like : "n, k, kn, knk, knkkn, knkknknk"
Please try below code will help you:
<?php
function fibStr($n, $arr) {
$resp = $arr;
for($ij= 2;$ij<$n;$ij++)
{
$resp[$ij] = $resp[$ij-1].$resp[$ij-2];
}
return implode(", ",$resp);
}
echo fibStr(6, ["n", "k"]);
?>

Generate file JSON from PHP script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I generate this structure file JSON from PHP script?
Example JSON:
{
"messages":[
{
"attachment":{
"type":"image",
"payload":{
"url":"#"
}
}
}
]
}
Thanks :)
That should work.
$a = ["messages" => [["attachment" => ["type" => "image", "payload" => ["url" => "#"]]]]];
$b = json_encode ($a);

I am working on IP create in form and want explode some data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
It's my store method where I am getting IP through request from my view
public function store(Request $request)
{
$ip['ip_range'] = $request->input('ip_range');
$ip['min_ip'] = $request->input('ip_range');
$ip['max_ip'] = $request->input('ip_range');
$ip_data = Ip::create($ip);
session()->flash('msg', ' Successfully created');
return view('ip.index');
}
In above I want if IP comes as
192.168.2.9
192.168.1.2
It should be saved as 2 values .... Mean it should separate it on /r/n and where I found /n I create a new value and so on.
And next thing is that if user enter as
192.168.1.0-3
Here a - comes at last one 192.168.1-3 should be save in ip_range and 192.168.1.0 in min_ip while 192.168.1.3 as max_ip.
I hope this is what you were looking for:
public function store(Request $request) {
$ip['ip_range'] = $request->input('ip_range');
$arrIps = explode("\r\n", $ip['ip_range']);
foreach($arrIps as $strIp) {
$arrRange=explode("-",$strIp);
if(count($arrRange)>1){
$ip['min_ip']= $arrRange[0];
$arrDot=explode(".",$arrRange[0]);
$arrDot[3]=$arrRange[1];
$ip['max_ip']= implode(".",$arrDot);
}
else
$ip['min_ip']=$ip['max_ip']="";
$ip_data = Ip::create($ip);
}
session()->flash('msg', ' Successfully created');
return view('ip.index');
}

how to send string response in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to send the string response of a particular request from ftp Interface. I am using below code..
if($s == 'Successfull') {
$rid = 's'.$request_id;
}
if($s == 'Unsuccessfull') {
$rid = 'e'.$request_id;
}
echo "<b style='font-size: 16px;color:#59AB8F;'>Your Request ID:".$rid.".......<b>\n";
printf("<br>");
header($rid);
Why not set a response code with a JSON response?
if($s == 'Successfull'){
http_response_code(201);
$data = [ 'id' => $request_id ];
}
else {
http_response_code(400);
}
if (isset($data)) {
header('Content-Type: application/json');
echo json_encode($data);
}
That would be the normal way of handling an API POST response. 201 signifies a resource was created, 400 signifies a bad request (you can change this if a different response code matches better). Then the client can read in the JSON data and get the id.

PHP Array values from file_get_contents [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I declared one variables like this
echo $OPTIONS="500=>250.00, 1000=>500.00,2500=>1100.00,5000=>2250.00";
and
I got this variables through file_get_contents() functions.
$contents = file_get_contents(SERVICE_URL."options_config.php?options=".$OPTIONS);
$package=array($contents)
foreach($package as $pack=>$price)
{
echo $pack;
}
But I got 0 values. What is the problem?
print_r($package);
The result is :
Array ( [0] => 500=>250.00, 1000=>500.00,2500=>1100.00,5000=>2250.00 )
I want the result like this
500 as 250.00
1000 as 500.00
I think what you are looking for is serialize and unserialize
Example: test.php
<?php
// Handle Get Request
// This portion of your code can be on another file
//
if (isset($_GET['getOptions']))
{
$myOptions = array(
500 => 250.00,
1000 => 500.00,
2500 => 1100.00,
5000 => 2250.00
);
exit(serialize($myOptions));
}
// Sample Usage
$options = file_get_contents('http://localhost/test.php?getOptions');
$options = unserialize($options);
// Debug
var_dump($options);
?>
Outputs:

Categories