嗨,我正在创建一个生成器表单来替换我拥有的一些 CSS 代码......它会找到所有的类和 id 以及点,并将 .class 放在它们前面......
现在它只替换了我将限制设置为-1的第一场比赛......为什么它忽略它?
html:
<form action="get_html.php" method="post" id="form">
html:<textarea rows="50" cols="80" id="html_box" name="html" type="text" align="texttop"></textarea>
<input id="button" type="submit" value="submit"></input>
</form>
get_html.php
<?php
$html= $_POST["html"];
$string = (string)$html;
$patterns = array();
$patterns[0] = '/^[.]/';
$patterns[1] = '/^[#]/';
$patterns[2] = '/,/';
$replacements = array();
$replacements[0] = '.class .\1';
$replacements[1] = '.class #\1';
$replacements[2] = ', .class \1';
$str= preg_replace($patterns,$replacements, $string, -1);
?>
<textarea rows="50" cols="80"><?php echo $str; ?></textarea>