preg_repace单引号问题。

时间:2016-06-06 11:18:56

标签: php regex

我想用反斜杠单引号替换单引号。当我做一个回声时我尝试正确显示下面的PHP代码但是当我做一个error_log时它会显示一个额外的反斜杠。不确定我是否做错了或者error_log函数正在逃避它。

$cont="a'b";
// display a\'b
echo preg_replace("/'/", "\\'" , $cont);
// displays a\\'b in apache error log file
error_log(preg_replace("/'/", "\\'" , $cont);

1 个答案:

答案 0 :(得分:0)

您的代码中存在语法错误。您在最后一行错过了一个结束括号,您调用了$(function () { $('#container').highcharts({ chart: { type: 'column', zoomType: 'x' }, colors:[ '#d8d826' ], legend:{ itemStyle:{ fontSize:'10px', font:'10pt', color:'#000000' } }, title:{ style:{ fontSize:'0px' } }, subtitle:{ style:{ fontSize:'0px' } }, xAxis: { // NOTE: There is an interesting bug here where not all labels will be shown when the chart is redrawn. // I'm not certain why this is occuring, and I've tried different methods to no avail. I'll check with Highcharts. categories: ['1960','1961','1962','1963','1964','1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016'], tickmarkPlacement: 'on', tickInterval: 1, minRange: 1 // set this to allow up to one year to be viewed }, yAxis: { min: 15, title: { text: 'Number', style:{ fontSize:'0px' } } }, tooltip: { shared: false, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: [{ name: 'data by year', data: [49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,50] }] }); // on change handler for both sliders $('.mySlider').bind('change', function(e) { e.preventDefault(); var chart = $('#container').highcharts(); // use setExtremes to set the x-axis ranges based on the values in the sliders chart.xAxis[0].setExtremes($('input[name="slider1"]').val(), $('input[name="slider2"]').val()); }); });

完整代码:

error_log()

截屏:enter image description here