felix
felix

Reputation: 13

php cookie have quote remove

I try to display content from a cookie with php but it shows me with quotes.>"name"

<?php echo $_COOKIE['name_user']; ?>

What can I do to not appear quotes?

Upvotes: 0

Views: 164

Answers (1)

ByteHamster
ByteHamster

Reputation: 4951

Use ltrim and rtrim:

$name = $_COOKIE['name_user']; // "name"
$name = ltrim($name, '"');     //  name"
$name = rtrim($name, '"');     //  name
echo $name;

// Everything in one line:
echo ltrim(rtrim($_COOKIE['name_user'], '"'), '"');

Easier solution (suggested by Fluffy):

echo trim($_COOKIE['name_user'], '"');

Upvotes: 1

Related Questions