WordNet access using php - php

I tried to access the wordnet dictionary as mentioned in: Calling wordnet from php (Wordnet class or API for PHP).
It worked fine through command line. Then I tried to use the php function shell_exec() as below to access the dictionary:
<?php
$output=shell_exec("\Program Files (x86)\WordNet\2.1\bin\wn");
echo $output;
?>
This displays the search option like -ant, -hyp, and so on.i.e it worked fine
But when I tried to add the search option in the above command(as below) it did not work:
<?php
$output=shell_exec("\Program Files (x86)\WordNet\2.1\bin\wn star -synsn");
echo $output;
?>
or even when I gave space in the command like:
$output=shell_exec("\Program Files (x86)\WordNet\2.1\bin\wn ")
it did not work.
Can you please help me what may be the reason for this and any suggestion for the solution?

ok i got the solution now.the problem was because of the spaces between the command.So i handled them as below:
$cmd = '"C:/Program Files (x86)/WordNet/2.1/bin/wn" "home" "-synsn"';
$output=shell_exec($cmd);
thanks to all who responded to my query

Related

PHP show_source not working on my server (Altervista)

I am trying to display the PHP source of a file inside a page. I am using show_source function in this way:
<?php
$nomefile = $_REQUEST['nome'];
show_source($nomefile);
?>
When I try this code on my local PC (using USBWebserver v8.6), it works smoothly, displaying the PHP code of the page. But when I try it on my remote webserver (Altervista), I only get an empty page.
I even try to substitute variable $nomefile with name "visite.php", which is the name of a file residing in the same folder, but still I get no result? I try with echo show_source(...), but no result again.
Is there an error in my code? Or maybe show_source is not compatible with all version of PHP? Is there any easy alternative?
Thanks a lot
Giancarlo Perlo - Italy

file_get_html only working for certain URL (OVH issue?)

I am using simple_html_dom script to gather certain information from external pages.
The script I have been using worked pretty well until today. I tried to look for where the error came from and it seems the file_get_html function is not working anymore, only on certain URLs.
The basic code I am using is:
<?php include_once('../simple_html_dom.php');
echo file_get_html('http://www.hltv.org/match/2295100-')->plaintext; ?>
When executing this, I have a blank page on my OVH shared server. It seems the page returns a 503 error, even if the page actually exists. I am able to extract the content of the page from other servers (like AWS) however. What troubles me is that it's been working for 4 months now without any issue.
I made sure the MAX_FILE_SIZE of the simple_html_dom was increased but could not find any solution to this.
Any idea to solve the issue?
Thanks!
Try this:
<?php
include_once('../simple_html_dom.php');
$result = file_get_html('http://www.hltv.org/match/2295100-');
echo $result->plaintext;
?>

Including File PHP not work - work by using comment tag - bug?

ISSUE:
PHP Warning: ........ failed to open stream: No
such file or directory in
/home/.
I found many titles discussed related on the topic I pick now. I tried to look into the path and make sure everything went okay. I also checked the server connectivity, bandwidth or everything related to hosting or DNS stuff and tried it again. But it was still not working.
However, when I use php comment tag, as in #, unbelievable, it really really works! That's why I want to find out why it could be like that.
Here's the actual path:
/home/appacybe/public_html/in-grammar/user_validator.php on line 2
Previous (error) report codes:
<?php
include('../user_validator.php');
...
?>
<!DOCTYPE html>
...
</html>
Working codes:
index.php:
<?php
################# start ####################
############################################
################# end ####################
include('../user_validator.php');
...
?>
<!DOCTYPE html>
<!--bla bla
./end -->
Inside user_validator.php:
<?php
echo 'hallo';
?>
Successfully Output:
- Hallo
- other text below it.
Some suggests to use Magic Constant and many says that I should use require, require_once or others.
But when I use that php commentary tag, I found it works successfully.
What's wrong? Is this a bug? or I just don't know how to be on the right PHP programming?
Please let me know.
This is the simple thing for you perhaps but really I still question; what's wrong with it or "me" ?
NEW POSSIBILITIES:
I tested to VPS or Dedicated Server and it works by using common function. But always got failed in share hosting - but working with the comment tag.
What's going on? :(
Any help would be so great!
You can use dirname(FILE) to obtain the path of the script that line is called in. You can then reference relative paths from there e.g.
include (dirname(__FILE__) . '../user_validator.php');
According to me, In some cases where $_SERVER['DOCUMENT_ROOT'] is not set or is not what you would expect (i.e. not set in CLI or old IIS, or invalid in certain CGI setups) then server might not be able to find out related path of include file. So, it will give an error.

samba web client - setup connection in php script

I have to establish connection with Samba server from my php script in order to download some files into my local server.
Actually its first time I have heard of something like Samba so I Tried to look for a opensource code that I could make use of.
Here it is what I have found: First class - smbclient.php and I tried code posted on the page:
<?php
require_once ('smbclient.php');
$smbc = new smbclient ('//10.0.1.1/example', 'exampleuser', 'examplepassword');
if (!$smbc->get ('path/to/desired/file.txt', '/tmp/localfile.txt'))
{
print "Failed to retrieve file:\n";
print join ("\n", $smbc->get_last_stdout());
}
else
{
print "Transferred file successfully.";
}
?>
Adjusting it into my needs ( server, user, password), all i got is
Failed to retrieve file:
Fatal error: Call to undefined method smbclient::get_last_stdout()
Then I found out about smbwebclient.php project which looks awesome and can be found here.
And this class looks good but the problem is that I have no idea how to use it. Can anyone post it example connection or link to tutorial?
To get files from a samba server, you can try to use a smb wrapper, like the one here but changing the deprecated splits with explodes. Then you can include your php file using this code:
include_once('smb.php');
include( 'smb://user:password#server/folder/file.php');
Reviving old thread but I think I found the solution, the code must have changed since the pot was made on the blog:
print join ("\n", $smbc->get_last_stdout());
should now be
print join ("\n", $smbc->get_last_cmd_stdout());

Get windows title using php doesn't work on browser call

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.

Categories