How do I find a matching string like a search engine for a description keyword?
As follows: How to match the "Germany" and the "ball" in any of the following 180 characters of the most occurrences of the position segment?
PHP Code
$varchar = ' Germany and Denmark both won in the first match 1-0, in the second round, Germany 2-1 defeated Holland, two team game, Germany, although received 6 points, but still failed to guarantee the line, the last one if lost to Denmark is still out of the possibility. Denmark's last 0-2 after two goals, but the final 2-3 lost to Portugal, the group was handed over to Portugal. Denmark wants to qualify for the line must strive to defeat Germany, fortunately they also do not lack the feeling of defeating Germany. In the last 3 games of the two teams, Denmark's astonishing 2 wins and 1 levels prevailed, the most recent of which was in August 2010, when Denmark scored two goals behind. The last time the two teams played in the European Cup was the 1992 European Cup final, at the height of the Danish fairy tale, with the Nordic 2-0 beating Germany to win. In the first two games in Germany, Gomez became the biggest highlight. Super Mario in two consecutive games swept Germany 3 goals, the horror is that he scored 3 goals only spent 6 feet shot. Gomez is currently ranked first in the 3-ball rankings, and since the European Cup Muller scored 4 goals in 1976, Germany has not scored more than 3 players in a single European Cup for 36 years. Left Front Podolski in the previous two games are full-game, the national team played 99 games, the field is expected to achieve hundred. The two sides did not make a big adjustment to the starting lineup, the German team just because Boateng suspended and sent to Germany, Denmark is only replaced by Mr. Paulson, the team of the elder Rommedahl injured in the absence. The German striker Podolski the national team's 100th game, and the youngster Bender first in the national team. The first 2 minutes, Khedira off the frontier to the left cross, the middle of no one to get the ball, after the point Muller chest stop after the left foot volley slightly higher. The first 5 minutes, the Danish left corner, Turner far point header Gongmen was Neuer get. 1 minutes later, Germany quickly counter-attack, Ernie left straight, Podolski crosses, Kjaer Rescue ineffective, Muller in front of 3 meters shot by Anderson magical solution. For the first 12 minutes, the outer left foot of the Gomez restricted area was high. ';
------Solution--------------------
Identify the keywords, then Substr_count ($string, $key); Segment accumulation, save the largest segment
------Solution--------------------
Okay, I don't get it.
I thought the segmentation, is the individual paragraphs, the separate calculation can
------Solution--------------------
At least limit the length of the description, this is the "beauty of programming" in the shortest summary problem, or similar deformation requirements.
First find out where all the Germans and the ball in the string appear, then prepare to leave, right hand pointing to the head, straight to the left, until the [left] contains two keywords, then left to start right, All the way up to any one keyword count to be reduced to 0 stop, continue to go right, as in the method.
------Solution--------------------
I don't know how your segmentation is defined.
The sample data you give is 5 natural segments, whichever is the case
Or do not consider the natural segment, but with every 180 characters for a paragraph
Or a starting point that can be sliding.
------Solution--------------------
The first step
PHP code
$ar = Preg_split ('/(Germany | ball)/', $varchar,-1, Preg_split _no_empty | Preg_split_delim_capture | preg_split_offset_capture);p Rint_r ($ar);