如何找到 PHP 中特定字符串中存在的 SMS 密钥
How to find the SMS keys present in the specific string in PHP
我有一个来自数据库的字符串,看起来像这样,
$string = "Hello ##USERNAME##, your subscription is closing by tommorow. Please renew your subscription before ##EXPIRYDATE##. Thank You.";
现在我只需要从字符串中提取键。比如##USERNAME##、##EXPIRYDATE##、##TICKETID##、##DUEAMOUNT## 等。
我有很多包含不同键的相关字符串(例如:##USERNAME##)。
请提供一个解决方案,从上面 PHP 中的字符串中提取键。
如果字符串有 ##VAR##
那么一个简单的正则表达式就足够了
$string = "Hello ##USERNAME##, your subscription is closing by tommorow. Please renew your subscription before ##EXPIRYDATE##. Thank You.";
preg_match_all('@##(\w+)##@',$string,$matches);
echo '<pre>',print_r( $matches,true ),'</pre>';
这个输出
Array
(
[0] => Array
(
[0] => ##USERNAME##
[1] => ##EXPIRYDATE##
)
[1] => Array
(
[0] => USERNAME
[1] => EXPIRYDATE
)
)
我有一个来自数据库的字符串,看起来像这样,
$string = "Hello ##USERNAME##, your subscription is closing by tommorow. Please renew your subscription before ##EXPIRYDATE##. Thank You.";
现在我只需要从字符串中提取键。比如##USERNAME##、##EXPIRYDATE##、##TICKETID##、##DUEAMOUNT## 等。
我有很多包含不同键的相关字符串(例如:##USERNAME##)。
请提供一个解决方案,从上面 PHP 中的字符串中提取键。
如果字符串有 ##VAR##
那么一个简单的正则表达式就足够了
$string = "Hello ##USERNAME##, your subscription is closing by tommorow. Please renew your subscription before ##EXPIRYDATE##. Thank You.";
preg_match_all('@##(\w+)##@',$string,$matches);
echo '<pre>',print_r( $matches,true ),'</pre>';
这个输出
Array
(
[0] => Array
(
[0] => ##USERNAME##
[1] => ##EXPIRYDATE##
)
[1] => Array
(
[0] => USERNAME
[1] => EXPIRYDATE
)
)