例如:
$str = "This is my string.";
$startafter = "This is";
$endbefore = ".";
我需要$output = "my sting";
(我会trim()
删除“我的”之前的空格)
我怎样才能在 PHP 中做到这一点?谢谢你。
preg_match("/".preg_quote($startafter)."(.*?)".preg_quote($endbefore)."/", $str, $output_array);
您可以使用 preg_replace() php 默认方法,例如
<?php
$test = '';
$test = preg_replace("/^$startafter/i",'',$str');
$test = preg_replace("/$endbefore$/i",'',$str');
echo $test;
?>
希望这能解决您的问题或类似的问题:)