好的,为了清楚起见,我举个例子
$email = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="157b74787055706d74786579703b767a78" rel="noreferrer noopener nofollow">[email protected]</a>';
$domain = strstr($email, '@');
echo $domain; // prints @example.com
$user = strstr($email, '@', true); // As of PHP 5.3.0
echo $user; // prints name
正如它所说,它使用 true 打印“@”之前的内容,使用空白打印 @ 之后的内容
我正在寻找一个函数来打印@本身,通过给它2个字符串并抓取它们之间的内容
像这样
$string= 'someXthing';
$tograb = phpfunction("some","thing");
echo $tograb; // should be printing X
^ 这不起作用,我只是写它来解释
最佳答案
我不知道有哪个 native 函数可以做到这一点,但您可以使用正则表达式
$string= 'someXthing';
preg_match("/some(.*)thing/",$string,$matches);
var_dump($matches[1]);
了解更多关于preg_match的信息
关于php - 有没有PHP函数可以找到中间字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10145587/