How to remove word String from var_dump?

Is there anyway to remove word string from var_dump?

‘last_name’ => string ‘Arora’ (length=6)
‘first_name’ => string ‘Vijesh’ (length=15)

Uhmmm…Why would you want to do that? It’s just telling you what the variable type of that instance of the array element is. It’s not like if you print the last_name element, it would print string ‘Arora’ (length=6). It’ll print Arora

I know it is the string, so that’s why I don’t want to see in var_dump.

Quite contrary, that’s why you always want to see it in var_dump() so it will tell you what is wrong when the type will be different.

if you’re not interested in type details, use var_export() or print_r(). but then you might miss invisible characters (like the NULL Byte)

I only use var_dump() for quick-and-dirty debugging and hacky personal-use-only scripts. (more for “inspection”, not “use”)

That is, when any “extra” information comes in handy or it doesn’t bother me to see it.

If you are using var_dump() to output something to a “real” page, you are using the wrong tool.

As others have posted, use some other way to output the value(s)

1 Like

How can I rid out of this problem

/Applications/XAMPP/xamppfiles/htdocs/php/view.php:11: // WTH, this path is showing in var_dump? :unhappy:
array (size=4)
‘age’ => int 31
‘career’ => string ‘web developer’ (length=13)

You should only be using var_dump for testing, so why do you want to remove important information?

1 Like

No idea what you are trying to do with var_dump. var_dump is for debugging. If you really want to output data, you’re better off using print or echo and declaring the variables with their key. This turns an array into a string based on the key you declare. Example

$array = array(
    'first_key' => 'Just a first key',
    'second_key' => 'Just a second key'
);

print($array['first_key']);

Or if you want to output an array, you might want to use print_r.


The path shouldn’t be displaying to the screen. Can we see your snippet please? This might help us understand why you want to use var_dump instead of the listed above.

1 Like

Not only with arrays but I am getting the path in everywhere using var_dump

Like this is the code

<?php
use Carbon\Carbon;
require 'libraries/Carbon.php';

$date = new Carbon('+10 days 12 hours');
var_dump($date);

and this is the output

http://image.prntscr.com/image/13d17eb3d52444c08b4fde3d9ee75f0b.png

Lots of people have already advised against adjusting the output of var_dump and they are absolutely correct. However, it could be instructive to see how you would capture and adjust the output.

<?php
error_peporting(E_ALL);
$person = [
    'last_name'  => 'Arora',
    'first_name' => 'Vijesh',
    'age' => 13,
];
// Capture the results of var_dump
ob_start();
var_dump($person);
$varDumpResult = ob_get_clean();

// Make string go away per the requirement
$varDumpResultNoString = str_replace('string','',$varDumpResult);

// Show the results
echo $varDumpResult;
echo $varDumpResultNoString;

So this gives you what you asked for though if you examine the output it is probably not what you actually need.

By the way, there are prettier wrappers for var_dump available. For example: http://symfony.com/doc/current/components/var_dumper.html Might be worth while to learn how to load and use a component.

Have you modified any part of Carbon.php? If you modified it, you have to go through it and see where there is an out of some kind such as print, echo, print_r, or var_dump.

It doesn’t seem to be from your var_dump you are showing us. It seems to be coming from an earlier point in time. Which only means that it is being outputted from another file that is being included.

var_dump DOES NOT have the power to output the directories it is in. It only outputs whatever variable or constant you reference in it. Unless this could be a Mac thing. In which case, I shall test it myself.

By any chance is the system path being displayed by a debugger such as xdebug?

@vijesharora16 @Mittineague


Nope, it definitely is a Mac problem. Here’s my comparisons for Yosemite (Mac), Windows 10, and CrunchBang (Linux OS).


Yosemite (Mac)



Windows 10



CrunchBang (Linux)



All the same script. The only difference is on different OS and Mac seems to be the only one outputting different things on screen compared to the other 2 OS.

2 Likes

It can also happen on windows. @vijesharora16 have you got the xdebug php extension loaded?

Yeah yeah… xdebug was loaded and I think the path is showing from xdebug. Do you know how to turn it off ?

You have a lot of virtual families :smiley: I am also using Yosemite and Windows 10, I haven’t tested in Win10 yet.

xdebug isn’t the problem. I believe it’s Mac itself. I don’t have xdebug installed on my Sublime Text for all 3 OS, but my Yosemite is outputting the directory. This shouldn’t happen if xdebug isn’t installed, but it is for me even though I don’t have xdebug installed on my Sublime Text nor have I searched the term xdebug ever on my Yosemite.


You can all try it for yourselves as well. I believe OP’s problem lies within Mac.

I think it should be from xdebug because before I had never seen such type of path in Mac too

Are you sure? Because I don’t have xdebug installed as I have said and still get the same thing you get. I don’t have any packages installed on my Mac’s Sublime Text. Would it make any sense if I don’t have xdebug installed nor even have it ever exist in my search history? This could also be the root of your problem too. I believe it’s a Mac thing. Like different OS outputs different things via var_dump.