php bir desen yerine

3 Cevap

Suppose in a file there is a pattern as sumthing.c: and asdfg.c: and many more.. with *.c: pattern

Metin yourinput ile değiştirin ve php kullanarak dosyayı kaydetmek nasıl

Kalıptır *.c

teşekkürler ..

3 Cevap

Bir PHP string file_get_contents, *.c için yapmanız kullanarak yourinput içine dosyanın içeriğini okuyabilir dize değiştirme ve kullanarak dosyaya geri yazmak file_put_contents:

$filename = '...'; // name of your input file.
$file = file_get_contents($filename) or die();
$replacement = '...'; // the yourinput thing you mention in the quesion
$file = preg_replace('/\b\w+\.c:/',$replacement,$file);
file_put_contents($file,$filename) or die();

PHP'nin str_replace veya str_replace (onun bir regex desen durumda) kullanabilirsiniz. Bu iki işlevin sözdizimini kontrol ve girişi ile *. C değiştirin.

.c pattern should be something like /? (. C) $ /

İlk açık dosya almak ve onun içeriği:

$content = file_get_contents($path_to_file);

Içeriğini değiştirmek daha:

$content = preg_replace('/.*\.c/', 'yourinput');

Nihayet geri dosyaya kaydedebilirsiniz.

file_put_contents($path_to_file, $content);

Note: Bu yolu daha önce '.c' dize ve her şeyi karşılayan çünkü regexpi değiştirmeyi düşünebilirsiniz. Belki '/[a-zA-Z]*\.c/' istediğiniz şeydir.