PHPの特定のポイントでファイルにチェーンを挿入したい。
ここに例があります(私が試したこと):
$insert = "Example of Chain";
$fileContent = file_get_contents($file);
//Example of content: codecodecode <tag> EXAMPLE EXAMPLE </tag> code code code
//Result i need = codecodecode Example of Chain codecodecode
ご覧のとおり、タグのコンテンツとその nodeValue を削除し、$insert
. また、file_get_contents を使用する必要があることに注意してください。
アドバイスと裏技ありがとう
ここで試してみます。このコードは、ファイル コンテンツ内のタグを (file_get_contents によって) 検出し、コードを関数からのテキスト リターンに置き換えretrieveLinks
ますが、ファイル内のテキストを正しい位置に戻す方法がわかりません。
// '' の間にある場合は表示されないので、そのように自発的に配置します.. 間違いではありません
$start = 'タグ'; $end = '/タグ';
$startChain = strpos($fileContent, $start);
$endChain = strpos($fileContent, $end) + strlen($end);
$text = substr($fileContent, $startChain, $endChain - $startChain);
require_once("showISComment.php");
$newText = retrieveLinks($project);
$content = str_replace($text, $newText, file_get_contents($file));
//file_put_contents($file, $content);