PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 30, 2022

[FIXED] How do I check my php and pear version using C programming in Linux?

 August 30, 2022     c, linux, pear, php     No comments   

Issue

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!

Btw, I'm using dreamhost shared server if that might help and yes, it has gcc, php5.3 and pear 1.9.4 installed.


Solution

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:

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.



Answered By - David C. Rankin
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing