$str = “111|9|2212|1321424|5|”;
$reg = “Rice Cooker”;
$reg1 = “Fu Fu”;
$reg2 = “Year”;
preg_match_all(“/([0-9]+)\|/ isU”,$str,$arr);
print_r($arr);
Seek to match only 1. The rice cooker is no longer in the sea and has fallen 2. The wires and rice cooker rods are no longer 3. Should Sudiandan Company order rice cookers again?
Reply to discussion (solution)
$str = "111|9|2212|1321 424| 5|";$reg = "rice cooker";$reg1 = "no more";$reg2 = "that year";$sp = explode('|', $str);$inArr = array();foreach ($sp as $key => $value) { if(strpos($value,$reg) !== FALSE && strpos($value ,$reg1) !== FALSE && strpos($value,$reg2) !== FALSE){ array_push($inArr, $value); }}var_dump($inArr);
$str = "111|9|2212|1321 424|5|";$reg = "rice cooker";$reg1 = "no more" ;$reg2 = "Year";$sp = explode('|', $str);$inArr = array();foreach ($sp as $key => $value) { if(strpos($value,$reg ) !== FALSE && strpos($value,$reg1) !== FALSE && strpos($value,$reg2) !== FALSE){ array_push($inArr, $value); }}var_dump($inArr);
Is regular expression OK? Because this text may be 1MB or more, is it more efficient to use arrays or regular expressions?
Which one is more efficient than regular expressions? ? What if there are 1,000 arrays? Text regularity
$s = "111|9| 2212|1321424|5|";preg_match_all('/(?< =]*(?:(?:rice cooker|no more|then)[^|>]*){3}[^|>]*)>/U', $s, $ r);print_r($r[1]);
Array
(
[0] => The rice cooker sea is no longer the same as before
[1] => No more wires The rice cooker rods are different in different years
[2] => Su Niandan Company will not order to repurchase the rice cooker
)
$s = "111|9|2212|1321424 |5|";preg_match_all('/(?<=]*(?:(?:Rice cooker| No more|then)[^|>]*){3}[^|>]*)>/U', $s, $r);print_r($r[1]);
Array
(
[0] => The rice cooker market no longer suffers from the same decline as it did in the past
[1] => The wires and rice cooker rods are no longer the same as in the past
[2] => Sudandan Company ordered I won’t buy the rice cooker again
)
Mr. Xu has this flaw and can have 3 identical ones or 3 no longer have them
Formal language, especially its own rules
$s = "111|9|2212|1321424|5|";$a = explode('|', $s);$d = array( "rice cooker", "不了", "年");foreach($d as $c) $a = preg_grep("/$c/", $a);print_r($a);
Array
(
[1] => 9
[3] => 1321 424
[ 4] => 5
)
$s = "111|9|2212|1321424|5|";preg_match_all('/(?<=]*(?:(?:rice cooker|no more|then)[^ |>]*){3}[^|>]*)>/U', $s, $r);print_r($r[1]);
Array
(
[0] => The rice cooker market no longer suffers the same setbacks as it did in the past
[1] => The wires and rice cooker rods are no longer the same as in the past
[2] => Su Niandan Company no longer orders rice cookers
/> )
Boss, your regular expression meets the needs,,,, but now I want to take out the previous number at the same time, because this is the data ID….
Form Language, especially its own rules
$s = "111|9|2212|1321424|5|";$a = explode('|', $s) ;$d = array("rice cooker", "不了", "年");foreach($d as $c) $a = preg_grep("/$c/", $a);print_r($a) ;
Array
(
[1] => 9
[3] => 1321 424
[4] => 5
)
$s = “111|9|2212|1321|424|5”;
Formal language, especially its own rules
$s = "111|9|2212|1321424|5|";$a = explode('|', $s);$d = array(" Rice cooker", "不了", "年");foreach($d as $c) $a = preg_grep("/$c/", $a);print_r($a);
Array
(
[1] => 9
[3] => 1321 424
[4 ] => 5
)
Boss, your rules are too high-end. I spent a long time and finally figured it out myself
But next time No