简体   繁体   English

如何使用php分割单词?

[英]How to Split words using php?

I want to split a small word. 我想一句话。 My word is written bellow. 我的话写在下面。

{you: awesome; {你真棒; feeling good} 感觉很好}

I want to split above word to just get the word feeling good by using php 我想通过使用php拆分单词以使单词感觉良好

$arr = explode(';', trim("{you: awesome; feeling good}", '{}'));
$feel_good_string = trim($arr[1]);
echo $feel_good_string;

You can use explode() in PHP for split string. 您可以在PHP中使用explode()作为拆分字符串。

Example 1: 范例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

Example 2: 范例2:

$string = '{you: awesome; feeling good}'; // your string
$exploded = explode(";", $string);  // explode with ;
echo rtrim($exploded[1],"}"); // rtrim to remove ending } 

Other option would be.... 其他选择是...

$str = "{you: awesome; feeling good}";
$str = trim($str,"{}");
echo substr($str,strpos($str,";")+1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM