用'|'拆分字符串烧焦

时间:2012-09-26 14:33:47

标签: php split

我想用char“|”拆分跟随字符串但我得到了以下错误,有任何想法吗?

错误:

Warning: split() [function.split]: REG_EMPTY in E:\AppServ\www\admin\panelActions\editApplication.php on line 39

string:

|../../filesBank/_screenshots/com.beem.project.beem_screenshot_0.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_1.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_2.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_3.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_4.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_5.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_6.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_7.jpg

代码:

$__screenShots = split("|", $requestRow['appImages']);

4 个答案:

答案 0 :(得分:5)

形成关于split

的PHP DOC
  

自PHP 5.3.0起,此功能已被弃用。非常不鼓励依赖此功能。

尝试

$string = '|../../filesBank/_screenshots/com.beem.project.beem_screenshot_0.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_1.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_2.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_3.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_4.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_5.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_6.jpg|../../filesBank/_screenshots/com.beem.project.beem_screenshot_7.jpg' ;
var_dump(explode("|", $string));

输出

array
  0 => string '' (length=0)
  1 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_0.jpg' (length=67)
  2 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_1.jpg' (length=67)
  3 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_2.jpg' (length=67)
  4 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_3.jpg' (length=67)
  5 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_4.jpg' (length=67)
  6 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_5.jpg' (length=67)
  7 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_6.jpg' (length=67)
  8 => string '../../filesBank/_screenshots/com.beem.project.beem_screenshot_7.jpg' (length=67)

*如果您仍想使用split *

这是你使用它的方式

$string = split("[|]", $string);
var_dump($string);

你可以获得split() [function.split]: REG_EMPTY,因为你试图像这样使用它

   $string = split("|", $string);

答案 1 :(得分:2)

如果你使用一个关于某些正则表达式的函数,你应该真正理解你在这里使用了一个特殊字符:

  

| ---选择(也就是交替或设置联合)运算符匹配运算符之前的表达式或运算符之后的表达式。例如, abc|def匹配"abc""def"

POSIX Basic Regular Expressions Syntax

你想要做的是采用文字|字符,所以你需要逃避它:

split('\\|', ...)

请注意不推荐使用split函数(POSIX风格的正则表达式函数),使用explode时,可以在您的情况下实现非常相似的功能。如果没有,请使用preg_split

答案 2 :(得分:0)

尝试使用explode()函数 - 几乎相同

答案 3 :(得分:0)

警告,[函数] split()[声明] REG _ [ ] EMPTY在[您的文件] E中:第39行上的\ AppServ \ www \ admin \ panelActions \ editApplication.php。

所以,不要使用空的正则表达式。