我有這樣的:的preg_replace:只在花backets刪除評論
$text = 'This is some text /*Comment 1 */ . Some more text{ This is to let you know that /* this is a comment*/. A comment /*this one is */ can be anything }. So the next thing { This is to let you know that /* this is a comment*/. A comment /*this one is */ can be anything } is another topic. /*Final comment*/';
需要這樣:
$text = 'This is some text /*Comment 1 */ . Some more text{ This is to let you know that . A comment can be anything }. So the next thing { This is to let you know that . A comment can be anything } is another topic. /*Final comment*/';
嘗試這樣:
$text = preg_replace("/\/\*.*?\*\//", "", $text);
問題是,我試過的,是刪除所有的評論。我只想將{ }
內的評論刪除。這個怎麼做?
如果你有像' {/ *} * /}'? – Gumbo 2012-04-01 05:40:02
沒有想到它。這種數據是意想不到的。在這種情況下可能的解決方案是什麼? – Devner 2012-04-01 06:44:08
這一切都取決於你。但是在定義這種語言時應該考慮這種情況。 – Gumbo 2012-04-01 06:47:28