PHP在字符串中包含“和'字符

I have a String in php variable. I want to add " and ' character before of the string variable and ' and " character after of my string variable. The following is my code but it fail to display what I wanted like "'String'"

$channel = """.$channel.""";
$channel = "\'".$channel."\'"
echo $channel

You're escaping them incorrectly (in the wrong order).

What you want is this:

$channel = '"\'' . $channel . '\'"';

Notice how we're escaping the ' ? That's because we are using it to supply the string -> '....'. We need to escape it otherwise it'd "end" the string there. Causing syntax errors.

Example/Demo.

    $channel = '"'.$channel.'"';
$channel = "\'".$channel."\'";
echo $channel;

i think the problem is you are foggeting to close your strings and you excapted them incorrectly