Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否有PHP函数来查找中间字符串?_Php_String_Strstr - Fatal编程技术网

是否有PHP函数来查找中间字符串?

是否有PHP函数来查找中间字符串?,php,string,strstr,Php,String,Strstr,好的,我来举个例子 $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com $user = strstr($email, '@', true); // As of PHP 5.3.0 echo $user; // prints name 正如它所说,它使用true打印“@”之前的内容,使用blank打印后面的内容@ 我在寻找一个函数来打印@本身,给它两个

好的,我来举个例子

$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com

$user = strstr($email, '@', true); // As of PHP 5.3.0
echo $user; // prints name
正如它所说,它使用true打印“@”之前的内容,使用blank打印后面的内容@

我在寻找一个函数来打印@本身,给它两个字符串,并抓住它们之间的什么

像这样

  $string= 'someXthing';
  $tograb = phpfunction("some","thing");
  echo $tograb; // should be printing X

^这不起作用,我写这篇文章只是想解释一下,我不知道有哪个本机函数可以做到这一点,但是你可以使用正则表达式

$string= 'someXthing';
preg_match("/some(.*)thing/",$string,$matches);
var_dump($matches[1]);
从互联网上阅读更多关于

function GetBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
        $r = explode($end, $r[1]);
        return $r[0];
    }
    return '';
}

对于您所说的示例,您可以使用strpos打印X,如下所示:

$string = 'someXthing';

$start = strpos($string, "some") + strlen("some");
$end = strpos($string, "thing", $start);
$tograb = substr($string, $start, $end - $start);

echo $tograb;

X将被打印。

我真的很想看到一个您可以使用它的案例。此外,只需使用regex,你需要的是一个regexcheck这个线程。这有点工作,但如何使它只打印X而不打印一些thing@LiliAbedinpour变量$matches是一个数组,因此您可以
echo$matches[1]
查看匹配的字符串。ohhh抱歉,是的,现在找到了,谢谢我很好,但我认为应该有一个功能,我想它将主要是需要在未来!无论如何谢谢你