0

I'm a beginner in PHP. I want to use var_dump($var1) to get the format

string(10)"I Love PHP"

When i use the function in sublime text editor, the output format is:

string 'I Love PHP' (length=10)

Note: I'm using xampp and xdebug.

Nick
  • 4,820
  • 18
  • 31
  • 47
  • considering var_dump is for debugging, not showing users, why would you want this? –  May 29 '18 at 22:03
  • 1
    I don't think `var_dump` has any ability to be formatted (by default). I would assume your IDE (sublime, in this case, I guess?) is formatting the result after the fact. (as in, it can tell it is the result of `var_dump` and parses it and displays the result in a format it likes). If that's the case, your question might better be asked as "how can I specify the format sublime text editor uses for var_dump results?" – Anthony May 29 '18 at 22:06
  • Thanks @Anthony , I understand from this that it has nothing to do with var_dump() – Aml Hussein May 29 '18 at 22:11
  • @smith ,I just want this specific format – Aml Hussein May 29 '18 at 22:14

1 Answers1

0

If you are dealing with scalar types (string, integers, floats), you can do something like:

echo "'" . gettype($var) . "'(length=" . strlen((string) $var) . ')';

Doing this for every case would require more work, like testing if it is an array and replacing strlen() with count(), and deciding what you want to do with objects and resources.

fab2s
  • 838
  • 2
  • 8
  • 14