Question Overflow
Question Overflow

Reputation: 11275

How do I Remove the Enclosing Single Quotes from a String?

I have an email address enclosed in single quotes:

$email = "'[email protected]'";

I want to remove the single quotes to obtain:

$email = "[email protected]";

I think [email protected] itself may also contain single quotes if I am not wrong. Is there a neat solution for this?

Upvotes: 1

Views: 568

Answers (2)

deceze
deceze

Reputation: 522635

Remove surrounding quotes if present:

$email = trim($email, "'");

Upvotes: 3

codaddict
codaddict

Reputation: 455460

You can use the function trim() to remove the enclosing single quotes:

$email = trim($email, "'");

Upvotes: 6

Related Questions