div class php style background F0F5FA font-size 11px border 1px dotted

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<div class="php" style="background: #F0F5FA;font-size:11px;border:1px dotted #5E8ACA;margin:0px;padding:0px;padding-left:5px;"><form action="pr_5.php" method="GET" /><br />
<label>Исходный текст </label><textarea name="massive" required >мама мало мыла раму. Петя кушал абрикос</textarea><br><br />
<label>Искать комбинацию </label><input type="text" name="str" required value="ма" /> <br><br />
 <br />
<input type = "submit" value="Искать" /><br />
</form><br />
<p><br />
<span style="color: #000000; font-weight: bold;"><?php</span><br />
<span style="color: #666666; font-style: italic;">//Вариант 1</span><br />
 <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'massive'</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span><br />
 <span style="color:#;">if</span> <span style="color: #009900;">(</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'massive'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span><br />
 <span style="color: #000088;">$mas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">(</span><span style="color: #0000ff;">" "</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Разбиваем текст на слова и записываем в массив</span><br />
 <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'str'</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span><br />
 <span style="color:#;">echo</span> <span style="color: #0000ff;">"<br>  Вы ввели: "</span><span style="color: #339933;">.</span><span style="color: #990000;">count</span><span style="color: #009900;">(</span><span style="color: #000088;">$mas</span><span style="color: #009900;">)</span><span style="color: #339933;">.</span><span style="color: #0000ff;">" слов. Комбинация: <b><span style="color: #006699; font-weight: bold;">$str</span></b> была найдена в следующих словах: <br>"</span><span style="color: #339933;">;</span><br />
 <span style="color: #000088;">$kol</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
 <span style="color:#;">for</span> <span style="color: #009900;">(</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;"><=</span> <span style="color: #990000;">count</span><span style="color: #009900;">(</span><span style="color: #000088;">$mas</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span><br />
 <span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">(</span><span style="color: #000088;">$mas</span><span style="color: #009900;">[</span><span style="color: #000088;">$i</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><br />
 <br />
 <span style="color:#;">if</span> <span style="color: #009900;">(</span><span style="color: #000088;">$pos</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>  <span style="color: #009900;">}</span> <span style="color:#;">else</span> <span style="color: #009900;">{</span> <span style="color:#;">echo</span> <span style="color: #000088;">$mas</span><span style="color: #009900;">[</span><span style="color: #000088;">$i</span><span style="color: #009900;">]</span><span style="color: #339933;">.</span><span style="color: #0000ff;">"<br>"</span><span style="color: #339933;">;</span><br />
 <span style="color: #000088;">$kol</span> <span style="color: #339933;">++;</span><span style="color: #009900;">}</span><span style="color: #339933;">;</span><br />
 <span style="color: #009900;">}</span><span style="color: #339933;">;</span><br />
 <br />
 <span style="color:#;">if</span><span style="color: #009900;">(</span><span style="color: #339933;">!</span><span style="color: #000088;">$kol</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span><span style="color:#;">echo</span> <span style="color: #0000ff;">"Увы, но не найдено ниодного соответсвия"</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span><span style="color: #339933;">;</span><br />
 <span style="color: #009900;">}</span><span style="color: #339933;">;</span><br />
 <span style="color:#;">echo</span> <span style="color: #0000ff;">"<br>"</span><span style="color: #339933;">;</span><br />
 <br />
 <span style="color: #666666; font-style: italic;">//Вариант 2</span><br />
<span style="color:#;">if</span> <span style="color: #009900;">(</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'massive'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span> <br />
<span style="color: #000088;">$mystring</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'massive'</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$findme</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'str'</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">(</span><span style="color: #000088;">$mystring</span><span style="color: #339933;">,</span> <span style="color: #000088;">$findme</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><br />
<br />
<span style="color:#;">if</span> <span style="color: #009900;">(</span><span style="color: #000088;">$pos</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span><br />
    <span style="color:#;">echo</span> <span style="color: #0000ff;">"Строка '<span style="color: #006699; font-weight: bold;">$findme</span>' не найдена в строке '<span style="color: #006699; font-weight: bold;">$mystring1</span>'"</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">}</span> <span style="color:#;">else</span> <span style="color: #009900;">{</span><br />
    <span style="color:#;">echo</span> <span style="color: #0000ff;">"Строка '<span style="color: #006699; font-weight: bold;">$findme</span>' найдена в строке '<span style="color: #006699; font-weight: bold;">$mystring1</span>'"</span><span style="color: #339933;">;</span><br />
    <span style="color:#;">echo</span> <span style="color: #0000ff;">" в позиции <span style="color: #006699; font-weight: bold;">$pos</span>"</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">}</span><br />
<span style="color: #009900;">}</span><span style="color: #339933;">;</span><br />
  <span style="color: #000000; font-weight: bold;">?></span></div>