【发布时间】:2016-02-10 10:17:10
【问题描述】:
我想拆分一个小字。我的话写在下面。
{你:真棒;感觉不错}
我想通过使用 php 来拆分上面的单词来获得 feeling good 这个词
【问题讨论】:
-
explode(";","you: awesome; feel good");
-
它的完整字符串? {你太棒了;感觉不错}
标签: php
我想拆分一个小字。我的话写在下面。
{你:真棒;感觉不错}
我想通过使用 php 来拆分上面的单词来获得 feeling good 这个词
【问题讨论】:
标签: php
$arr = explode(';', trim("{you: awesome; feeling good}", '{}'));
$feel_good_string = trim($arr[1]);
echo $feel_good_string;
【讨论】:
其他选择是......
$str = "{you: awesome; feeling good}";
$str = trim($str,"{}");
echo substr($str,strpos($str,";")+1);
【讨论】:
您可以在 PHP 中使用explode() 来分割字符串。
示例 1:
$string = '{you: awesome; feeling good}'; // your string
preg_match('/{(.*?)}/', $string, $match); // match inside the {}
$exploded = explode(";",$match[1]); // explode with ;
echo $exploded[1]; // feeling good
示例 2:
$string = '{you: awesome; feeling good}'; // your string
$exploded = explode(";", $string); // explode with ;
echo rtrim($exploded[1],"}"); // rtrim to remove ending }
【讨论】: