简体   繁体   English

创建正则表达式

[英]Create Regular Expression

I need a little help. 我需要一点帮助。 I have an expression that is 我有一个表达是

$orderline_val->products[$x]->product_options[2]->value

It generates a kind of string. 它生成一种字符串。 What I need is a regular expression that removes every "new line" character, every (') apostrophy comma. 我需要的是一个正则表达式,它删除每个“换行符”,每个撇号逗号。 On the other hand it also places a pipe on every 40th character. 另一方面,它还在每第40个字符上放置一个管道。

Any help? 有什么帮助吗? I was thinking to use preg_replace but could not generate a right expression. 我当时想使用preg_replace,但无法生成正确的表达式。

Here is the code that I tried. 这是我尝试过的代码。

str_replace("&,',/n/r", "+",$orderline_val->products[$x]->product_options[2]->value);

Let me know, Thanks in Advance. 让我知道,在此先感谢。

$str = str_replace(array("\n", "'"), array("", ""), $orderline_val->products[$x]->product_options[2]->value);
$parts = str_split($str, 40); // Or 39...
$piped_str = implode("|", $parts);

// Not sure if you want the next line, but in any case:
$orderline_val->products[$x]->product_options[2]->value = $piped_str;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM