首页 技术教程 实用代码 注册破解 正则表达式 网址导航 电子书籍

preg_replace——执行正则表达式的搜索和替换

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit]) 在 subject 中搜索 pattern 模式的匹配项并替换为 replacement。如果指定了 limit,则仅替换 limit 个匹配,如果省略 limit 或者其值为 -1,则所有的匹配项都会被替换。  replacement 可以包含 n 形式或(自 PHP 4.0.4 起)$n 形式的逆向引用,首选使用后者。每个此种引用将被替换为与第 n 个被捕获的括号内的子模式所匹配的文本。n 可以从 0 到 99,其中&nbs...
类别:网页编程 - PHP技术    查看:135    更新:2014-05-19

PHP全文搜索和替换代码

<?php exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode); if ($errorCode){ if ($errorCode == 1){ echo "Possibly no files were found with $oldword in them<BR>\n"; } echo "OS Error: $errorCode<BR>\n"; echo "Check 'man errno' and count down<BR>\n"; echo "Usually paths/permissions<BR>\n"; } while (list(,$path) = each($results)){ $parts = explode(':', $path); $path = $parts[0]; $fp = fopen($path, 'r') or print("Cannot read $path<BR>\n"); if ($fp){ $data = fread($fp, filesiz...
类别:网页编程 - PHP技术    查看:96    更新:2014-05-04