PHP explode string with tags using UTF8 between them

后端 未结 4 1787
梦谈多话
梦谈多话 2021-01-28 09:32

in php i want to explode string with tag using utf-8 between them, for example, in this text:

$content = \"فهرست اولhi my name is          


        
4条回答
  •  [愿得一人]
    2021-01-28 09:48

    You can try the following function, it should meet your needs well. Basically you should split the array using as the delimiter, and each item in the resultant array will be what you require, but the heading tag will be stripped since it is what you did your split on, so you need to add it back. There are comments explaining what the code is doing.

    function get_what_mahdi_wants($in_string){
    
      $mahdis_strings_array = array();
    
      // Split string at occurrences of ''
      $mahdis_strings = explode('', $in_string);
      foreach($mahdis_strings as $mahdis_string){
    
        // if '' is found at start of string, empty array element will be created. Skip it.
        if($mahdis_string == ''){ continue; }
    
        // Add back string element with '' tag prepended since exploding on it stripped it.
        $mahdis_strings_array[] = ''.$mahdis_string;
      }
      return $mahdis_strings_array;
    }
    

提交回复
热议问题