How to Split words using php?

前端 未结 3 908
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 20:39

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

相关标签:
3条回答
  • 2021-01-16 20:54
    $arr = explode(';', trim("{you: awesome; feeling good}", '{}'));
    $feel_good_string = trim($arr[1]);
    echo $feel_good_string;
    
    0 讨论(0)
  • 2021-01-16 20:54

    Other option would be....

    $str = "{you: awesome; feeling good}";
    $str = trim($str,"{}");
    echo substr($str,strpos($str,";")+1);
    
    0 讨论(0)
  • 2021-01-16 20:57

    You can use explode() in PHP for split string.

    Example 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:

    $string = '{you: awesome; feeling good}'; // your string
    $exploded = explode(";", $string);  // explode with ;
    echo rtrim($exploded[1],"}"); // rtrim to remove ending } 
    
    0 讨论(0)
提交回复
热议问题