When i run php -a It brings up a handy shell for testing code quickly along with a history of every line I type. Is there any way to clear this history?
Using php 5.5.9 if this makes any difference
On my linux laptop, there's a ~/.php_history that contains the ... history.
For clear history you can use readline_clear_history()
readline_clear_history ( void );
This function clears the entire command line history.
Return Values
Returns TRUE on success or FALSE on failure.
For Windows users, you can find the .php_history file in your home directory as well. I found mine at C:\Users\{my_name}\.php_history
Related
I'm trying to set auto-complete for readline to enable a user to navigate through the filesystem directories when running a script through CLI.
I found out PHP has a function called readline_completion_function for this purpose but every time I hit tab to complete a word, it adds a space at the end.
readline_completion_function(function() {
return ['aaa', 'bbb', 'ccc'];
});
// Input a or b or c
readline('Add char and tab: ');
I've create fiddle for you to test this:
https://repl.it/#rmdev/Readline-Completion-Tab-Extra-Space
I saw on Python readline configs that there's a configuration called set_completer_delims to set a character to be apendend after tab is hit but in PHP there are only two configurations and none of them apply to the completer delims.
I also saw some posts referring to this as a known bug but it seems it has been fixed on most of the integrations although I don't see any reference to a fix for the PHP one.
Is there any way to remove this space?
I'm using PHP 7.2.12 on a Mac.
is it possible to write a PHP script that checks if the PC's firewall is disabled and then output yes/no into a checkbox on the webpage? (Hosting my own web server using WAMP)
Currently what i have in mind is create a .bat file that checks if firewall is turned off
using:
netsh advfirewall show public
then check if the State shown on CMD is On / OFF and return results to the web-page's checkbox.
Thing is i have no idea how do i go about doing the check state and return results.
Please advise. Also open to other ideas / solutions that could provide similar results.
PS: Am a beginner at PHP scripting and only started learning python today and project is due in 3 weeks. Also would be nice if you could link full code solutions if you know of any. I learn faster through referencing.
You can use this command to get only the status of the public profile :
"netsh advfirewall show public state"
This command can be used in a python script with the subprocess module :
result = subprocess.check_output(["netsh", "advfirewall", "show ", "allprofiles", "state"].decode('utf-8')
The result will be a string, using regex you will be able to get the value from it.
https://docs.python.org/3/library/re.html
Example of regex :
status = re.search('state[ ]*([A-Za-z])*', result).group(1)
I'm trying to get some "repl-like" feature for PHP, inside vim.
Basically, what I want is to be able to visually select a part of my script, execute it, and see the result in a separate buffer.
But I don't want to execute the whole current file (so :!php % doesn't do the trick ...)
I found the vim-quickrun plugin, which seems to greatly fit that need, but can't make it work and when looking for more documentation, most of the result I get are in japanese (I don't speak japanese :( ... )
For now, I have installed the plugin via Vundle, but have not added any extra configuration to my .vimrc
From inside a file, I can type
...
echo 'hello quickrun sh test'
...
=> visual select the date line, and type
:QuickRun sh
I got my hello world printed, all fine
But if I do
...
echo 'hellow quickrun php'
...
=> visual select ...
:QuickRun php
I just get a buffer with just the same text that I typed, no execution ...
Does someone already achieved something like this ?
Thanks a lot !
EDIT :
PHP is correctly added to my PATH. Added the 2 config lines suggested below ... Sadly, it doesn't change anything :(
You need to put the php flags around your php code, like any php script (it always starts in plain text mode):
...
<?php
echo 'hellow quickrun php';
?>
....
Then you can select only one part with QuickRun, but don't forget to select the flags as well.
I don't use that plugin, but I think you need to configure something like this in your ~/.vimrc:
let g:quickrun_config = {}
let g:quickrun_config.php = {'command' : 'php'}
and have the php executable in your PATH.
The following solution does not use vim-quickrun but allows you to visually select, execute and see the result just as you like. You need vim-slime with phpsh :
First, install the vim-slime plugin. It allows to send lines and visually selected chunks of code from VIM to a screen or tmux session.
Now install screen: On Ubuntu, do sudo apt-get install screen.
Open a terminal and start screen with a session name: screen -S sessionname.
Open a second terminal and start vim. Write some code, visually select it and press <C-c><C-c>, that is two times CTRL+C. You will be asked for the session name, use sessionname as before. The selected lines will be sent to the first terminal just as if you had written them directly there.
To make use of this functionality, you need to start an interactive PHP shell in the first terminal, such as phpsh.
My problem is I need to fetch FOOBAR2000's title because that including information of playing file, so I create a execute file via Win32 API(GetWindowText(), EnumWindows()) and it's working good.
TCHAR SearchText[MAX_LOADSTRING] = _T("foobar2000");
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam)
{
TCHAR buffer[MAX_TITLESTRING];
GetWindowText(hwnd, buffer, MAX_TITLESTRING);
if(_tcsstr(buffer, SearchText))
{
// find it output something
}
return TRUE;
}
EnumWindows(WorkerProc, NULL);
Output would look like "album artis title .... [foobar2000 v1.1.5]"
I created a php file like test.php, and use exec() to execute it.
exec("foobar.exe");
then in console(cmd) I use command to execute it
php test.php
It's working good too, same output like before.
Now I use browser(firefox) to call this php file(test.php), strange things happened.
The output only foobar2000 v1.1.5, others information gone ...
I think maybe is exec() problem? priority or some limitation, so I use C# to create a COM Object and register it, and rewrite php code
$mydll = new COM("FOOBAR_COMObject.FOOBAR_Class");
echo $mydll->GetFooBarTitle();
still same result, command line OK, but browser Fail.
My question is
Why have 2 different output between command line and browser. I can't figure it out.
How can I get correct output via browser.
or there is a easy way to fetch FOOBAR2000's title?
Does anyone have experience on this problem?
== 2012/11/28 edited ==
follow Enno's opinion, I modify http_control plug-in to add filename info, original json info is "track title".
modify as following
state.cpp line 380 add 1 line
+pb_helper1 = pfc::string_filename(pb_item_ptr->get_path());
pb_helper1x = xml_friendly_string(pb_helper1);
# 1: when firefox opens the php and it gets executed, it the context depends on the user which runs the php-container (apache), this is quite different from the commandline call which gets executed in your context
# 2 and 3: there seems to be more than one way for getting the title: use the foobar-sdk and create a module which simply reads the current title per api, then write your result in an static-html-document inside your http-root-folder OR use the http-client inside the sdk, with it, you do not need a wabserver, even better use a already implemented module: for instance foo_upnp or foo-httpcontrol
Good luck!
If your webserver runs as a service, in windows you need to enable "allow desktop interaction" for the service. Your php script runs as a child of the webserver process when requested via browser.
They gave me some tasks over a huge site realized with Magento.
I use Netbeans with Xdebug to debug (I'm on lubuntu oneiric btw) and I'm finding myself quite fine with all my tasks.
It happened to me to face a task concerning a class redeclaration and I lost a lot of time in finding the right file to change.
Just to learn how to do it correctly:
the task was to change the meta keywords, starting from a code like
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
With Netbeans debugger I can easily open the file containing getKeywords() which has:
public function getKeywords()
{
if (empty($this->_data['keywords'])) {
$this->_data['keywords'] = Mage::getStoreConfig('design/head/default_keywords');
}
return $this->_data['keywords'];
}
Now I couldn't find an easy way to go on through debugging in both cases :(
In particular my case is that $this->_data['keywords'] is not empty on the page I had to correct ..
so how can I easily know how this object is created and in particular who fills _data['keywords']?
It took me long time to find the right file by myself.
I'm not so expert in debugging, so maybe I could do it with netbeans w/ xdebug, but I cannot figure it out.
Thanks
open up terminal and
grep 'setKeywords(' app/code/ -rsn
this will reveal you the locations where this variable is set or used
grep -ri "Keywords" * | grep -v cache
'-r' means recursive
'-i' means case insensitive
'*' means any file name
'| grep -v cache' means strip out any references into the cache directory
You could temporarily create the method:
public function setKeywords($s) {
echo sprintf('<pre>%s</pre>', print_r(debug_backtrace(), true));
exit;
}
Add this code to same class that has getKeywords() so that when someone adds data via this function, you will see the backtrace and figure out how it happened