public static function getReplaceChunk($review, $replace_chunks) { return $review; $r = '<p><h4>総評</h4>' . PHP_EOL . $review["content"] . '</p>' . PHP_EOL . '<p><h4>長所</h4>' . PHP_EOL . $review["content"] . '</p>' . PHP_EOL . '<p><h4>短所</h4>' . PHP_EOL . $review["content"] . '</p>'; $r = "test"; $points = '<ol class="point">' . PHP_EOL; foreach ($replace_chunks as $val) { $str = preg_split('/-/', $val); $t = $r; while (true) { $_str = SplitStr($t, $str[0], $str[1]); if (!preg_match("/(<h4>長所|<h4>短所)/", $_str)) { break; } else { $t = $_str . $str[1]; } } $p1 = $str[0] . $_str . $str[1]; if (!preg_match("/" . trim($p1) . "/", trim($points))) { $eot = ""; if (!preg_match("/。/", $str[1])) { $eot = SplitStr($r, $str[1], "。") . "。"; } $points .= '<li class="lr' . $str[2] . '">' . $str[0] . $_str . $str[1] . $eot . '</li>' . PHP_EOL; } } $points .= "</ol>" . PHP_EOL; $review['points'] = $points; return $review; }
<?php /** * Write a procedure SplitStr(S, W, N) that creates an array W of all words being contained in a string S. * The array W of strings and its size N are output parameters. A word is defined as a character sequence that * does not contain blank characters and is bounded by blank characters or the string beginning/end; the string * S is assumed to contain no more than 10 words. Using this function, output the amount N of words in the given * string S and also all these words. */ include 'helper.php'; function SplitStr($S, &$W, &$N) { $W = explode(' ', trim($S)); $N = sizeof($W); } SplitStr('fdagv sardgr dsgvb rdg rag bsd frgbr dsbfd bzrt sbrsdbgr easw', $a, $b); print_r($a); var_dump($b);