PHP preg_replace和explode函数 [英] PHP preg_replace and explode function

查看:108
本文介绍了PHP preg_replace和explode函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些像这样的原始数据

I have some raw data like this

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

我的意图是删除\ u002522https \ this之间的每个字符串的反斜杠"\"和前7位.为此,输出将仅为https.

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.

如果只有\ u002522 \这样的7位数字,则输出将为空.

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] => 


)

我希望此结果用于构建URL.我已经尝试过使用preg_replaceexplode函数来获得预期的结果,但是我失败了.

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.

推荐答案

$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);

这篇关于PHP preg_replace和explode函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆