0

我有一个包含 49 个文件夹的项目,每个文件夹都有一个名为 index.php 的文件

所有 index.php 文件几乎相同,除了一部分会根据其所在的文件夹而变化。

<?php include_once("/home/bgarch/public_html/galleryheader.html"); ?>
<?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?>

</head>
<body>


<div class="header">
    <?php include_once("/home/bgarch/public_html/header.html"); ?>
</div>

<div class="clear"></div>

<div class="displaywrapper">
    <?php include_once("content.html"); ?>
</div></div>    

<div class="clear"></div>

<?php include_once("/home/bgarch/public_html/footer.html"); ?>

在上面写着:“../culture/..”的第二行中,文化一词是变量,并且根据它所在的文件夹而有所不同。

我需要知道的是执行“在项目中查找/替换所有内容”,它会自动将每个“index.php”文件中的所有文本替换为以下内容“

<?php include_once("http://www.bgarchitect.co.nz/subPage/index.php"); ?>

在过去的 2 个小时里,我一直在试图找出正则表达式来实现这一点,但到目前为止还没有成功。也许不可能这样做?

无论如何,我想我会在这里问一个问题,希望它实际上比我预期的要容易得多。因此,非常感谢任何帮助/指针/提示或技巧。

感谢阅读,詹尼斯

4

1 回答 1

1

如果我理解正确,您想用单词 subPage 替换单词文化(即当前目录)?

您可以在 TextMate 包的帮助下做到这一点。

Bundles > Bundle editor > Edit commands,然后添加一个新命令。将此添加为命令。我认为它可以满足您的需求。您必须将命令的输入设置为Entire document并将输出设置为Replace document

#!/bin/bash

sed "s/"${TM_DIRECTORY##*/}"/theWordYouWanToReplaceTheDirWith/g" | cat
于 2009-03-18T08:19:02.580 回答