我想从 file_get_contents 中删除文本

I want to remove text from a file_get_contents

这是我的代码:

<?php include 'parser.php'; 
$api = $_GET['api']; 
$file = file_get_contents("http://example.com");
echo $file; 
?>

还有这个returns

Example text: 111.111.111.111

如何删除示例文本并只显示 111.111.111.111?

如果文件中的所有内容都是此文本,那么您可以使用 str_replace()

$string = $file;
$newString = str_replace('Example text: ', '', $string);
echo $newString;

如果你每次都有相同的 return,你可以使用 str_replace 或者你可以使用 explode 并用 : 展开你的字符串。例如:

<?php include 'parser.php'; 
$api = $_GET['api']; 
$file = file_get_contents("http://example.com");
$res = explode(':',$file); 
echo $res[1];
?>

str_replace:

<?php include 'parser.php'; 
$api = $_GET['api']; 
$file = file_get_contents("http://example.com");
echo str_replace('Example text: ', '', $file);
?>