Ejemplo n.º 1
0
function makeTweet($tweets)
{
    $commonWords = getCommonWords($tweets);
    $sentence = createSentence($commonWords);
    $sentence = $sentence . " " . getRandomHashtag();
    return json_encode($sentence);
}
Ejemplo n.º 2
0
<?php

function getCommonWords($a, $b)
{
    $words1 = explode(" ", $a);
    $words2 = explode(" ", $b);
    foreach ($words1 as $str1) {
        foreach ($words2 as $str2) {
            if ($str1 == $str2) {
                $common[] = $str1;
            }
        }
    }
    return $common;
}
// var_dump($_GET);
$res = getCommonWords($_GET['str1'], $_GET['str2']);
echo '<h2>Список повторяющихся слов</h2><ul>';
foreach ($res as $word) {
    echo "<li>{$word}</li>";
}
echo '</ul>';
Ejemplo n.º 3
0
<?php

require_once __DIR__ . '/functions.php';
$str = [];
if ($_POST) {
    foreach ($_POST as $key => $value) {
        $str[] = $value;
    }
}
echo "Одинаковые слова: " . implode(getCommonWords($str[0], $str[1]), ' ') . '<br/>';
echo '<a href = "/">Назад</a> <br/>';
Ejemplo n.º 4
0
 * которые есть и в первом и во втором поле ввода.
 * Реализацию это логики необходимо поместить в функцию getCommonWords($a, $b),
 * которая будет возвращать массив с общими словами
 */
echo '<form action="" method="GET">';
echo '<textarea name="first" rows="10" cols="45">' . '</textarea>';
echo '</br>';
echo '</br>';
echo '<textarea name="second" rows="10" cols="45">' . '</textarea>';
echo '</br>';
echo '</br>';
echo '<input type="submit">';
echo '</form>';
if ($_GET) {
    $firstText = $_GET['first'];
    $secondText = $_GET['second'];
    getCommonWords($firstText, $secondText);
}
function getCommonWords($a, $b)
{
    $a = explode(' ', $a);
    $b = explode(' ', $b);
    $result = array_intersect($a, $b);
    if ($result) {
        echo '<pre>';
        print_r($result);
        echo '</pre>';
    } else {
        echo 'одинаковых слов нет';
    }
}
Ejemplo n.º 5
0
    <textarea name="textRight" id="" cols="30" rows="10">Леня Космос сумкин Федор Гриша Петя Яся Вася Рита сакура Алладин</textarea>
    <br>
    <label>Case sensitive
        <input type="checkbox" name="case" <?php 
echo isset($_GET['case']) ? 'checked' : '';
?>
 >
    </label>
    <input type="submit" value="Do it">
    <p>
        <?php 
if (sizeof($_GET) !== false) {
    if (isset($_GET['textLeft']) && isset($_GET['textRight'])) {
        $a = trim(strip_tags($_GET['textLeft']));
        $b = trim(strip_tags($_GET['textRight']));
        $case = isset($_GET['case']) ? true : false;
        if (sizeof($wordsArr = getCommonWords($a, $b, $case)) != false) {
            foreach ($wordsArr as $word) {
                echo $word . ' ';
            }
        } else {
            echo 'Общих слов не обнаружено';
        }
    }
}
?>
    </p>
</form>
</body>
</html>
Ejemplo n.º 6
0
            }
        }
    }
    return $result;
}
if ($_GET) {
    $str1 = !empty($_GET['text1']) ? $_GET['text1'] : null;
    $str2 = !empty($_GET['text2']) ? $_GET['text2'] : null;
    if ($str1 == null || $str2 == null) {
        echo "enter fields";
    } else {
        $a = explode(' ', $str1);
        $b = explode(' ', $str2);
        var_dump($a);
        echo "common words: ";
        $arr = getCommonWords($a, $b);
        if ($arr) {
            foreach ($arr as $k => $v) {
                if ($k == count($arr) - 1) {
                    echo $v;
                } else {
                    echo $v . ", ";
                }
            }
        } else {
            echo " - ";
        }
    }
}
?>
</body>
Ejemplo n.º 7
0
$arr2 = explode(" ", $text2);
// var_dump($arr1, $arr2);
function getCommonWords($a, $b)
{
    foreach ($a as $key1 => $item1) {
        foreach ($b as $key2 => $item2) {
            if ($a[$key1] == $b[$key2]) {
                $arr3[] = $a[$key1];
            }
        }
    }
    var_dump($arr3);
    echo "Первый вариант <br>";
    $result = array_unique($arr3);
    var_dump($result);
    echo "Второй вариант <br>";
    asort($arr3);
    $last = "";
    foreach ($arr3 as $key3 => $item3) {
        if ($last != $arr3[$key3]) {
            $rez[] = $arr3[$key3];
            $last = $arr3[$key3];
        } else {
            unset($arr3[$key3]);
        }
    }
    ksort($arr3);
    var_dump($arr3);
}
getCommonWords($arr1, $arr2);
Ejemplo n.º 8
0
            if ($word_1 == $word_2) {
                $common[] = $word_1;
            }
        }
    }
    return $common;
}
if ($_POST) {
    $str1 = isset($_POST['userMessage1']) ? $_POST['userMessage1'] : null;
    $str2 = isset($_POST['userMessage2']) ? $_POST['userMessage2'] : null;
    if ($str1 == null || $str2 == null) {
        echo "enter fields";
    } else {
        $text1 = explode(' ', strtolower($str1));
        $text2 = explode(' ', strtolower($str2));
        echo "common words: ";
        $arr = getCommonWords($text1, $text2);
        $result = array_unique($arr);
        if ($result) {
            foreach ($result as $key => $value) {
                if ($key == count($result) - 1) {
                    echo $value;
                } else {
                    echo $value . ", ";
                }
            }
        } else {
            echo "No common words";
        }
    }
}
Ejemplo n.º 9
0
    <p>Second area</p>
    <p><label><textarea rows="5" cols="45" name="second"></textarea></label></p>
    <input type="submit" value="Отправить">
    </form>
<?php 
/*1. Создать форму с двумя элементами textarea. При отправке формы скрипт должен выдавать только те слова, которые есть и в первом и во втором поле ввода. Реализацию это логики необходимо поместить в функцию getCommonWords($a, $b), которая будет возвращать массив с общими словами.*/
function getCommonWords($a, $b)
{
    $a_words = explode(" ", $a);
    $b_words = explode(" ", $b);
    $z = array();
    if ($a != null && $b != null) {
        for ($i = 0; $i < count($a_words); $i++) {
            for ($j = 0; $j < count($b_words); $j++) {
                if ($a_words[$i] == $b_words[$j]) {
                    $z[] = $b_words[$j];
                }
            }
        }
    }
    if ($z != null) {
        echo "<pre>";
        print_r($z);
        echo "</pre>";
    } else {
        echo "нет совпадений";
    }
}
if (isset($_POST["first"]) && isset($_POST["second"])) {
    getCommonWords($_POST["first"], $_POST['second']);
}
Ejemplo n.º 10
0
        <br>
        <input type="submit" value="Найти общие слова!" name="submit">
    </form>
    </body>
    </html>
<?php 
function getCommonWords($a, $b)
{
    $a = explode(' ', $a);
    $b = explode(" ", $b);
    $common = [];
    foreach ($a as $index => $itemA) {
        foreach ($b as $i => $itemB) {
            if ($itemA == $itemB) {
                $common[] = $itemA;
            }
        }
    }
    $common = array_unique($common);
    foreach ($common as $index => $item) {
        echo $index + 1 . ") {$item}<br>";
    }
}
if (isset($_POST['submit'])) {
    if (!empty($_POST['first']) and !empty($_POST['second'])) {
        echo "<p>Общие слова:</p>";
        getCommonWords($_POST['first'], $_POST['second']);
    } else {
        echo "<br> Не введены нужные данные";
    }
}
Ejemplo n.º 11
0
<!DOCTYPE html>
<html>
<head><title>Task 1</title></head>
<body>
<form action="" method="get">
    <textarea name="firstText"></textarea>
    <textarea name="lastText"></textarea>
    <input type="submit">
</form>
</body>
</html>
<?php 
function getCommonWords($a, $b)
{
    $words = array();
    $a = explode(" ", $a);
    foreach ($a as $k) {
        if (strstr($b, $k)) {
            $words[] = $k;
        }
    }
    return $words;
}
if ($_GET) {
    var_dump(getCommonWords($_GET['firstText'], $_GET['lastText']));
}
Ejemplo n.º 12
0
    <body>
<form action="" method="post">
<u>Ваше имя:</u><br>
<input type="text" name="name" placeholder ="Введите ваше имя"/><br><br>
<u>Комментарий:</u><br>
<textarea input type="text" name="comment" placeholder ="Введите ваш комментарий"></textarea><br>
<u>Другой комментарий:</u><br>
<textarea input type="text" name="text" placeholder ="Введите ещё один комментарий"></textarea><br>
	<input type="submit" value = "Отправить"/><br><br>	
</form>
    </body>
</html>
<?php 
/*
1. Создать форму с двумя элементами textarea. При отправке формы скрипт должен выдавать только те слова, которые есть и в первом и во втором поле ввода.
Реализацию это логики необходимо поместить в функцию getCommonWords($a, $b), которая будет возвращать массив с общими словами.
*/
function getCommonWords($a, $b)
{
    $comm = explode(" ", $a);
    $tex = explode(" ", $b);
    $result = array_intersect($comm, $tex);
    echo "<pre>";
    print_r($result);
    echo "</pre>";
}
if ($_POST) {
    $comment = $_POST['comment'];
    $text = $_POST['text'];
    getCommonWords($comment, $text);
}
Ejemplo n.º 13
0
<?php

function getCommonWords($a, $b)
{
    $string_1 = explode(" ", $a);
    $string_2 = explode(" ", $b);
    $res = [];
    foreach ($string_1 as $val_1) {
        if (in_array($val_1, $string_2)) {
            $res[] = $val_1;
        }
    }
    return $res;
}
echo "<pre>";
var_dump($_POST);
$res = getCommonWords($_POST['val_1'], $_POST['val_2']);
print_r($res);