开发者

remove double quotes around "function() { ... }"

开发者 https://www.devze.com 2023-02-10 21:46 出处:网络
Brain not working today - can anyone give me a regexp that would turn: {events:{click:\"function() { alert(\'hi\'); }\"}}}}}

Brain not working today - can anyone give me a regexp that would turn:

 {events:{click:"function() { alert('hi'); }"}}}}}

into:

 {events:{click:function() { alert('hi'); }}}}}}

any any other instances such as this in a string.

if this helps expand my question:

So far using this:

$replacement = '${1}:';
$json_options = preg_replace('/"(\w+)"\s*:/', $replacement, $json_options);

I have it turn this:

string(1051) "{"chart":{"renderTo":"tx_count","defaultSeriesType":"spline"},"credits":{"enabled":false},"series":[{"type":"spline","name":"Transactions Per Day","color":"#4572A7","data":[3,5,3,3,3,6,6,92,2]},{"type":"spline","name":"Value Per Day","yAxis":1,"color":"#89A54E","data":[30,232,172.99,30,160,550,596,2407.96,20]},{"type":"spline","name":"Average Value Per Day","yAxis":2,"color":"#AA4643","data":[10,46.4,57.7,10,53.3,91.7,99.3,26.2,10]}],"legend":{"enabled":true},"xAxis":{"labels":{"rotation":"-45"},"categories":["02\/02\/2011","03\/02\/2011","06\/02\/2011","07\/02\/2011","08\/02\/2011","09\/02\/2011","10\/02\/2011","11\/02\/2011","14\/02\/2011"]},"title":{"text":"Transactions Summary","align":"center","x":0,"y":20},"yAxis":[{"title":{"text":"Transactions","style":{"color":"#4572A7"}}},{"title":{"text":"Value","style":{"color":"#89A54E"}},"opposite":true},{"title":{"text":"Value (Average)","style":{"color":"#AA4643"}},"opposite":true}],"plotOptions":{"series":{"cursor":"pointer","point":{"events":{"click":"function() { alert('hi'); }"}}}}}"

into this (which is perfect),

string(947) "{chart:{renderTo:"tx_count",defaultSeriesType:"spline"},credits:{enabled:false},series:[{type:"spline",name:"Transactions Per Day",color:"#4572A7",data:[3,5,3,3,3,6,6,92,2]},{type:"spline",name:"Value Per Day",yAxis:1,color:"#89A54E",data:[30,232,172.99,30,160,550,596,2407.96,20]},{type:"spline",name:"Average Value Per Day",yAxis:2,color:"#AA4643",data:[10,46.4,57.7,10,53.3,91.7,99.3,26.2,10]}],legend:{enabled:true},xAxis:{labels:{rotation:"-45"},categories:["02\/02\/2011","03\/02\/2011","06\/02\/2011","07\/02\/2011","08\/02\/2011","09\/02开发者_高级运维\/2011","10\/02\/2011","11\/02\/2011","14\/02\/2011"]},title:{text:"Transactions Summary",align:"center",x:0,y:20},yAxis:[{title:{text:"Transactions",style:{color:"#4572A7"}}},{title:{text:"Value",style:{color:"#89A54E"}},opposite:true},{title:{text:"Value (Average)",style:{color:"#AA4643"}},opposite:true}],plotOptions:{series:{cursor:"pointer",point:{events:{click:"function() { alert('hi'); }"}}}}}"

now i need to remove double quotes round any function() { ... stuff... } that may be in the string.


You can $string = str_replace('"', "", $string);, no need for a regexp in this particular example.

Or try this then:

$string = str_replace(array('"function()','}"}'), array('function()', '}}'), $string);


This works for me:

<?php preg_replace('/"(function\s*?\(\)\s*?{.*?})"/', "$1", $string); ?>
0

精彩评论

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