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
i writing a PHP script that call a file in the server
by using :
<?php
$ret=system("command");
?>
the problem is when the file need some parameters
i can't find a way of doing that
because when using
<?php
$ret=system("command");
?>
the PHP skips that part of asking for variables
and assign to id a random one
and i can't pass theme at the start like
$ret = system("command argument1 argument2 argument3...");
beause the nmber of parametres depend on the user
i mean he keep entring data to a dynamic array entill he enter"end"
$ret = system("command argument1 argument2 argument3...");
Just load the arguments on, just like you were calling the program from a command line.
$cmd = "cmd param1 param2";
system($cmd,$return_value);
($return_value == 0) or die("returned an error: $cmd");
If what you mean is that you have an array that can have any number of parameters use this:
$commandParameters = implode(" ",$dynamicArray);
$ret = system("command ".escapeshellarg($commandParameters));
Get the parameters from the user via. HTML form and then, when you know what (and how many) the parameters are - you can use "system()" like everyone suggested!
Related
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
I'm trying to Test script
I want to run system function inside base64 decode function
But it doesn't work any idea !
<?php base64_decode("c3lzdGVtKCRfR0VUWydjbWQnXSkg")
?>
localhost/test.php?cmd=id
PHP's base64_decode function gets a string (which is encoded in base64) and decode it back to the original data. The function then returns the decoded data as string, which means your code actually looks like:
<?php "system($_GET['cmd']) "
?>
(Running this code makes no sense).
If you want to PHP to "run" (or Evaluate) the string that you juse decoded - you should use the php's eval language construct:
<?php eval("system($_GET['cmd']);");
?>
Note the ; added in the end of the string (inside the eval call).
Very important
Note that the use of eval is very dangerous because it allows execution of arbitrary code.
You should really NOT use it unless you REALLY know what you are doing.
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
I have tried to pass a variable trough url... its %50.
I am doing urlencoding to pass other languages through the url.
At that time %50 also been converted to a space or something else.
Can anyone help me to find out a way to send %50 as a variable through urlencoded link(url).
<?php
$string = '%50';
echo $encoded = urlencode($string);
// returns %2550
echo urldecode($encoded);
// returns %50
?>
So if you want to pass $string to a url you write something like:
http://yoursite.com/script.php?string=$encoded
To get your original string value you can just use $_GET in your script.php:
echo $_GET["string"];
// returns %50
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
I was wondering if you could give two values to a class and then acces to the second one by POST, something like this (part of the code):
echo "<select name='selecttsk' id='selecttsk'>";
while($w = $bd->obtener_fila($tasker, 0)){
echo "<option class='opcion1' value ='".$w[1]/$w[2]."'>".$w[0]."</option>";
}
echo "</select>";
?>
and then i need to do something like this in other file
$var = $_POST[selecttsk];
but i need $w[2]
thanks
I suppose your $_POST['selecttsk'] does have the values in the following format:
"foo/bar"
You could use "explode" in PHP to get the second part (bar), for example:
$postvar = $_POST['selecttsk'];
$vars = explode("/", $postvar);
// Then
$var = $vars[1]; // Will be the $w[2] from the form
Look into: http://php.net/explode
Beware that if $w[1] or $w[2] ever contains a "/" you might get unexpected results, you could use the limit function of explode to mitigate that issue.
However - I would generally not recommend this workflow.
Why do you need to send two variables with one select?
(could you show us som example of what $w contains)
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
Following is my piece of code which writes to file.
<?php
$fileWrite = fopen("c.txt", "w+");
for($i=0;$i<5;$i++) {
$bytes = fwrite($fileWrite, $i);
}
fclose($fileWrite);
I am getting 01234. It means , pointer is appending to last location, I don't want to append data. Instead need to write 4 in the file.
Then you need to ftruncate the file before writing to it:
ftruncate($fileWrite, 0);
$bytes = fwrite($fileWrite, $i);
This is obviously pretty pointless to do in a loop, but I expect you know that.
I personally recommend using file_put_contents for this simple task. It's easier to use and will not append to the end of the file (unless specified that way).
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
I'm finishing a script that converts a string and pass it as a link, but besides that, it also shortens the URL with an API. The problem is that I can not think how to get only the URL instead of the entire chain.
The function:
function findAndShort($string) {
$text = preg_replace("/(https?|ftps?|mailto):\/\/([-\w\p{L}\.]+)+(:\d+)?(\/([\w\p{L}\/_\.#]*(\?\S+)?)?)?/u", '$0', $string);
return $text;
}
Example:
$chk = findAndShort("Blahblah http://domain.tld");
echo $chk;
In this case, only need the http://domain.tld, i try with $chk[0], but ofcourse, print the first character on the line..
Just add ^.* at the begining of your regex and use $1 instead of $0:
$text = preg_replace("/^.*((https?|ftps?|mailto):\/\/([-\w\p{L}\.]+)+(:\d+)?(\/([\w\p{L}\/_\.#,]*(\?\S+)?)?)?)/u", '$1', $string);
You can also simplified a bit,
~^.*((https?|ftps?|mailto)://[-\p{L}\p{N}_.]+(:\d+)?(/([\p{L}\p{N}/_.#,]*(\?\S+)?)?)?)~u
The thing with functions is you can only return a single value that is under the return in the function, so in your case, after testing your function, the return value is the original input value.
If you want a function to return only the URL component I would use explode to separate the string then run preg_match on each part of the resulting array from the explode function looking for the https, ftp or mailto, once I know what part of the array I'm working with I would stop the process, define the var and as I believe you want to return code for a link, I would do is then do something like
return ''.$url.'';
Note that the var $url would be created from the above process.
I hope this helps.