你好我创建一个发电机形式,以取代 一些CSS代码我有...它会发现所有的 class和id以及点,并将其放置的.class 在他们面前。 ..preg_replace函数替换所有匹配
现在它只是取代第一场比赛 我已设置限制为-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>
preg_replace在哪里? – madfriend 2012-07-23 08:06:01
我的不好,编辑对不起 – 2012-07-23 08:09:14
通常是错误的方法 – diEcho 2012-07-23 08:15:03