1

Searched all over to see if anyone had done this yet. I want to split the information from mysqli_stat() up into items so I can echo them out on a new line for each item. Right now this command

printf("System status: %s\n", mysqli_stat($database));

Out puts like so

System status: Uptime: 58913 Threads: 1 Questions: 16008 Slow queries: 0 Opens: 476 Flush tables: 1 Open tables: 464 Queries per second avg: 0.271

Is there a way to break this into items so I can print them like so

System status
----------------
Uptime: 58913
Threads: 1
Questions: 16008
Slow queries: 0
Opens: 476
Flush tables: 1
Open tables: 464
Queries per second avg: 0.271
Cœur
  • 37,241
  • 25
  • 195
  • 267
Kaboom
  • 674
  • 6
  • 27
  • @Machavity, I don't like that duplicate target - there are other spaces in the returned string that *shouldn't* be changed to new line characters. Beyond that, I'm interrupting OP's question as "How to parse individual bits of information out of `mysqli_stat()`'s return value" (which could the be rendered onto each their own lines), which would be totally on topic and even useful. Voting to reopen this. – HPierce Jan 16 '17 at 18:08
  • @HPierce If that were the case, then it's a duplicate of [this question](http://stackoverflow.com/questions/5290342/php-split-delimited-string-into-key-value-pairs-associative-array) – Machavity Jan 16 '17 at 18:22
  • I don't see it as a duplicate of the referenced question since it could be parsed without regex using explode. – Sloan Thrasher Jan 16 '17 at 18:27
  • The string returned seems to separate each element with two spaces. So you could use *explode* to parse it into the individual parts: $ms = mysqli_stat($database); $ms1 = explode(' ',$ms); echo "

    \$ms1:

    ".print_r($ms1,true)."
    \n"; You could also step through the array $ms1 if you want to format the output.
    – Sloan Thrasher Jan 16 '17 at 18:29
  • @Machavity, I think that target would be *better* but still inappropriate. There's no clear delimiter in the string (`:` would be closest, but the first `:` isn't delimiting anything and would throw off the regex). I also think that parsing the return value of a built in PHP function is worthy of a specific answer rather than directing people to a general reference of any and all types of string parsing. Even then, I could imagine *plausible* answers recommending a specific query to MySQL's internal tables to get this information-but that type of answer would be wildly inappropriate on that Q. – HPierce Jan 16 '17 at 18:36
  • 1
    @HPierce I'd be more inclined to reopen if it were shown that other parsing methods can't do the job. I'm still not convinced this isn't a dupe but you've made some good arguments thus far. If the OP can show something not working, I'll gladly reopen – Machavity Jan 16 '17 at 18:57
  • @Machavity there is no function to sepeate this php built in funtion properly. As suggested by HPierce the `:` is too far from the value and causes issues with the way it's formatted for this application, something I am not keen on changing myself. I will most likely use regex to explode the value. Will report findings. – Kaboom Jan 16 '17 at 20:30

0 Answers0