0

例如:

$str = "This is my string.";
$startafter = "This is";
$endbefore = ".";

我需要$output = "my sting";(我会trim()删除“我的”之前的空格)

我怎样才能在 PHP 中做到这一点?谢谢你。

4

2 回答 2

0
preg_match("/".preg_quote($startafter)."(.*?)".preg_quote($endbefore)."/", $str, $output_array);
于 2013-10-24T11:25:00.587 回答
0

您可以使用 preg_replace() php 默认方法,例如

<?php

$test = '';
$test = preg_replace("/^$startafter/i",'',$str');
$test = preg_replace("/$endbefore$/i",'',$str');

echo $test;

?>

希望这能解决您的问题或类似的问题:)

于 2013-10-24T11:31:04.167 回答