说我有一个这样的字符串:正则表达式和PHP
$string = 'The /*quick*/ brown /*fox*/ jumped over the lazy /*dog*/.';
如何使用正则表达式找到的/ * * /的出现和替换每个值,像这样:
/*quick*/ with the value of $_POST['quick']
/*fox*/ with the value of $_POST['fox']
/*dog*/ with the value of $_POST['dog']
我已使用此模式尝试使用preg_replace:~/\*(.+)\*/~e
但它似乎并没有为我工作。
'的preg_replace( '|/\ *([^ *] +)\ */| E', '$ _POST [ “$ 1”]',$字符串)'精美把 – RobertPitt 2010-08-23 15:31:34
preg_replace('|/\ *([^ *] +)\ */| e','$ _POST [“$ 1”]',$ string)做得很好,谢谢。 – Mike 2010-08-23 15:39:28