我的代码在这里
$a = "@ABCD@" ;
echo $a ; // need print without @ @- ABCD
else
echo "please enter your text Type in between @ @" ;
这是如何在PHP中完成的?
答案 0 :(得分:1)
有多种方法可以做到这一点:
$a = "Testing @ABCD@ this";
$first = (strpos($a, '@') + 1);
$last = strpos(substr($a, $first, (strlen($a) - $first)), '@');
$match = substr($a, $first, $last);
if(!empty($match)) {
echo 'match';
} else {
echo 'no match';
}
正则表达式路线是:
$a = "Testing @ABCD@ this";
if(preg_match('/@([^@]+)[@]/', $a, $match)) {
echo 'match'; //$match[0];
} else {
echo 'No Match';
}