开发者

Output with single quote inside

开发者 https://www.devze.com 2023-03-25 03:05 出处:网络
I am using Symfony, but I think this is a general PHP problem to solve. $yaml[UtilInc::getSfEnvironment()][\'a\'][\'b\'] = \"\'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \'10\', \'1

I am using Symfony, but I think this is a general PHP problem to solve.

$yaml[UtilInc::getSfEnvironment()]['a']['b'] = "'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '15', '16'";

to make my yml file store:

a: { b: '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '15', '16'}

but it just kept storing it as:

a: { b: '''1'', ''2'', ''3'', ''4'', ''5'', ''6'', ''7'', ''8'', ''9'', ''10'', ''11'', ''12'', ''13'', ''15'', ''16'''}

I have tried various pattern such as escaping, used double quotes with combina开发者_运维技巧tion of single quotes, etc., but I still couldn't get the result I want.

Any ideas?

Thanks.


If we are talking about PHP without framework or whatever you are using, including ' in a string is as simple as this:

<?php
$v = "'a'";
echo $v;
?>

will output:

'a'

I don't know what symphony is, but if you are trying to assign an array to index b here's how:

$yaml[UtilInc::getSfEnvironment()]['a']['b'] = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '15', '16');

or if you want to have each element single quotes ':

$yaml[UtilInc::getSfEnvironment()]['a']['b'] = array("'1'", "'2'", "'3'", "'4'", "'5'", "'6'", "'7'", "'8'", "'9'", "'10'", "'11'", "'12'", "'13'", "'15'", "'16'");
0

精彩评论

暂无评论...
验证码 换一张
取 消