If possible, I don't want to use string detection method where you use string functions to detect the version in a given string output. If it isn't possible then please disregard what I just typed.
如果可能,我不想使用字符串检测方法,您可以使用字符串函数来检测给定字符串输出中的版本。如果不可能那么请忽略我刚输入的内容。
Is there a function to do it like uname() or do I have to write my own function? If so, please give me a headstart or you can make my life easier by teaching me how to do it. Thanks!
是否有像uname()那样的函数或者我必须编写自己的函数吗?如果是这样,请给我一个开头,或者通过教我如何做到这一点,你可以让我的生活变得更轻松。谢谢!
Btw, I'm using dreamhost shared server if that might help and yes, it has gcc, php5.3 and pear 1.9.4 installed.
顺便说一句,我正在使用dreamhost共享服务器,如果这可能会有所帮助,是的,它安装了gcc,php5.3和pear 1.9.4。
1 个解决方案
#1
1
Sorry to disappoint, but that is what you will need to do. The popen
function is your friend. Simply call "pear -V" in read mode with popen
and store the information in a buffer that you can easily parse to isolate the version numbers for both pear and PHP. It can be done much cleaner, but the gist of it is:
很抱歉让您失望,但这就是您需要做的事情。 popen功能是你的朋友。只需使用popen在读取模式下调用“pear -V”,然后将信息存储在缓冲区中,您可以轻松解析该缓冲区以隔离pear和PHP的版本号。它可以做得更干净,但它的要点是:
FILE *pfd;
char buffer[1024];
char *bp = buffer;
char tmp[100];
size_t len;
size_t line = 0;
if ((pfd = popen ("pear -V", "r")) == NULL) {
fprintf (stderr, "error: failed to open pipe.");
return 1;
}
while (fgets (tmp, 1023, pfd) != NULL && line < 2)
{
len = strlen (tmp);
strncpy (bp, tmp, len);
bp += len;
line++;
}
pclose (pfd);
printf ("\nbuffer:\n\n%s\n\n", buffer);
Output:
输出:
buffer:
PEAR Version: 1.9.4
PHP Version: 5.3.8
The parsing of the version numbers is left for you.
解析版本号留给你。
#1
1
Sorry to disappoint, but that is what you will need to do. The popen
function is your friend. Simply call "pear -V" in read mode with popen
and store the information in a buffer that you can easily parse to isolate the version numbers for both pear and PHP. It can be done much cleaner, but the gist of it is:
很抱歉让您失望,但这就是您需要做的事情。 popen功能是你的朋友。只需使用popen在读取模式下调用“pear -V”,然后将信息存储在缓冲区中,您可以轻松解析该缓冲区以隔离pear和PHP的版本号。它可以做得更干净,但它的要点是:
FILE *pfd;
char buffer[1024];
char *bp = buffer;
char tmp[100];
size_t len;
size_t line = 0;
if ((pfd = popen ("pear -V", "r")) == NULL) {
fprintf (stderr, "error: failed to open pipe.");
return 1;
}
while (fgets (tmp, 1023, pfd) != NULL && line < 2)
{
len = strlen (tmp);
strncpy (bp, tmp, len);
bp += len;
line++;
}
pclose (pfd);
printf ("\nbuffer:\n\n%s\n\n", buffer);
Output:
输出:
buffer:
PEAR Version: 1.9.4
PHP Version: 5.3.8
The parsing of the version numbers is left for you.
解析版本号留给你。