PHP preg_replace and explode function

假如想象 提交于 2019-12-25 17:42:52

问题


I have some raw data like this

\u002522\u00253A\u002522https\u00253A\u00255C\u00252F\u00255C\

My intention is to remove the backslash "\" and first 7 digit of every string between \u002522https\ this. For this the output will be only https.

If there is only 7 digit like this \u002522\ the output will be empty.

My final intention is to put every result in a array which is formatted for the above raw data like this

Array
(
      [0] => 
      [1] => 
      [2] => https
      [3] => 
      [4] => 
      [5] => 
      [6] => 


)

I want this result for constructing a URL. I have tried with preg_replace and explode function to get my expected result but I am failed.


回答1:


$text = '\u002522\u00253A\u002522https\u00253A\u00255C\u00252F\u00255C\\';
$text = preg_replace("#(\\\\[a-z0-9]{7})#is",",",$text);
$text_array = explode(",",trim($text,'\\'));
print_r($text_array);


来源:https://stackoverflow.com/questions/23426107/php-preg-replace-and-explode-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!